You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
910 B

var inherits = require('inherits');
var NestedError = function (message, nested) {
this.nested = nested;
Error.captureStackTrace(this, this.constructor);
var oldStackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
if (typeof message !== 'undefined') {
Object.defineProperty(this, 'message', {
value: message,
writable: true,
enumerable: false,
configurable: true
});
}
Object.defineProperties(this, {
stack: {
get: function () {
var stack = oldStackDescriptor.get.call(this);
if (this.nested) {
stack += '\nCaused By: ' + this.nested.stack;
}
return stack;
}
}
});
};
inherits(NestedError, Error);
NestedError.prototype.name = 'NestedError';
module.exports = NestedError;