index.js
function(message, originalError) {
  var stack;
  this.message = message;
  this.originalError = originalError;

  if (Error.captureStackTrace) {
    Error.captureStackTrace(this, this.constructor);
    stack = this.stack;
  } else {
    stack = new Error(message).stack;
  }

  if (Object.defineProperty) {
    Object.defineProperty(this, "stack", {
      configurable: true, // required for Bluebird long stack traces
      get: function() {
        if (this.originalError) {
          return stack + "\nCaused by:  " + this.originalError.stack;
        }

        return stack;
      },
      set: function(value) {
        stack = value;
      }
    });
  }
}
function(message, originalError) {
  var stack;
  this.message = message;
  this.originalError = originalError;

  if (Error.captureStackTrace) {
    Error.captureStackTrace(this, this.constructor);
    stack = this.stack;
  } else {
    stack = new Error(message).stack;
  }

  if (Object.defineProperty) {
    Object.defineProperty(this, "stack", {
      configurable: true, // required for Bluebird long stack traces
      get: function() {
        if (this.originalError) {
          return stack + "\nCaused by:  " + this.originalError.stack;
        }

        return stack;
      },
      set: function(value) {
        stack = value;
      }
    });
  }
}
function ( message , originalError ) { var stack ; this . message = message ; this . originalError = originalError ; if ( Error . captureStackTrace ) { Error . captureStackTrace ( this , this . constructor ) ; stack = this . stack ; } else { stack = new Error ( message ) . stack ; } if ( Object . defineProperty ) { Object . defineProperty ( this , "stack" , { configurable : true , // required for Bluebird long stack traces get : function ( ) { if ( this . originalError ) { return stack + "\nCaused by:  " + this . originalError . stack ; } return stack ; } , set : function ( value ) { stack = value ; } } ) ; } }
Create custom error type. Create a new object, that prototypally inherits from the Error constructor.
Create custom error type . Create a new object that prototypally inherits from the Error constructor .