dlueth
7/25/2017 - 3:30 PM

error.js

'use strict';

class CustomError extends Error {
  constructor(...args) {
    super(...args);

    Object.defineProperty(this, 'name', { value: this.constructor.name });
    Error.captureStackTrace(this, this.constructor);
  }
}

class ExtendedError extends CustomError {
  constructor(...args) {
    super(...args);
  }
}

try {
  throw new ExtendedError('gnarf')
} catch(err) {
  console.log(err.name);
  console.log(err);
}

module.exports = CustomError;