From 808d9ad9353206ddb56f08fcdbb6290edcf94ef7 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Mon, 28 Oct 2019 13:07:44 -0400 Subject: [PATCH] Define 'type' as a property on errors rather than a getter --- lib/Error.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/Error.js b/lib/Error.js index d96ce9a164..bc9a6ad88b 100644 --- a/lib/Error.js +++ b/lib/Error.js @@ -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; } /** @@ -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;