Skip to content

Commit

Permalink
Merge pull request #719 from stripe/richardm-type-property
Browse files Browse the repository at this point in the history
Define 'type' as a property on errors rather than a getter
  • Loading branch information
richardm-stripe authored Oct 30, 2019
2 parents 7ff0dd1 + 808d9ad commit 748411e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/Error.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ class StripeError extends Error {
super(raw.message);
// This splat is here for back-compat and should be removed in the next major version.
this.populate(...arguments);
}

// Allow `new StripeFooError(raw).type === 'StripeFooError'`
get type() {
return this.constructor.name;
this.type = this.constructor.name;
}

/**
Expand Down Expand Up @@ -71,12 +67,10 @@ class StripeError extends Error {
*/
static extend(options) {
const type = options.type;
class CustomError extends StripeError {
// eslint-disable-next-line class-methods-use-this
get type() {
return type;
}
}
class CustomError extends StripeError {}
Object.defineProperty(CustomError, 'name', {
value: type,
});
delete options.type;
Object.assign(CustomError.prototype, options);
return CustomError;
Expand Down

0 comments on commit 748411e

Please sign in to comment.