Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define 'type' as a property on errors rather than a getter #719

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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