Skip to content

Commit

Permalink
fix: generation of Error class
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Armstrong committed Jun 18, 2019
1 parent d427ce8 commit 8774891
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions jmespath.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,23 @@
}

function createErrorClass(className) {
var ExtendedError = function (message) {
Error.call(this, message);
this.name = className;
function ExtendedError(message) {
var instance = new Error(message);
instance.name = className;
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
if (Error.captureStackTrace) {
Error.captureStackTrace(instance, ExtendedError)
}
return instance;
};
ExtendedError.prototype = Object.create(Error.prototype);
ExtendedError.prototype.constructor = ExtendedError;
ExtendedError.prototype = Object.create(Error.prototype, {
constructor: {
value: Error,
enumerable: false,
writeable: true,
configurable: true,
},
});

return ExtendedError;
}
Expand Down

0 comments on commit 8774891

Please sign in to comment.