Skip to content

Commit

Permalink
Do not directly set Error properties.
Browse files Browse the repository at this point in the history
Fixes #231
  • Loading branch information
RubenVerborgh committed Sep 25, 2023
1 parent 192dbe7 commit bcbb096
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,16 @@ function createErrorType(code, message, baseClass) {

// Attach constructor and set default properties
CustomError.prototype = new (baseClass || Error)();
CustomError.prototype.constructor = CustomError;
CustomError.prototype.name = "Error [" + code + "]";
Object.defineProperties(CustomError.prototype, {
constructor: {
value: CustomError,
enumerable: false,
},
name: {
value: "Error [" + code + "]",
enumerable: false,
},
});
return CustomError;
}

Expand Down

0 comments on commit bcbb096

Please sign in to comment.