diff --git a/lib/Error.js b/lib/Error.js index 5b07c0b1d5..d96ce9a164 100644 --- a/lib/Error.js +++ b/lib/Error.js @@ -36,6 +36,13 @@ class StripeError extends Error { this.requestId = raw.requestId; this.statusCode = raw.statusCode; this.message = raw.message; + + this.charge = raw.charge; + this.decline_code = raw.decline_code; + this.payment_intent = raw.payment_intent; + this.payment_method = raw.payment_method; + this.setup_intent = raw.setup_intent; + this.source = raw.source; } /** diff --git a/test/Error.spec.js b/test/Error.spec.js index 7b70aa169e..e4fb1229a0 100644 --- a/test/Error.spec.js +++ b/test/Error.spec.js @@ -60,6 +60,16 @@ describe('Error', () => { ).to.be.instanceOf(Error.StripeIdempotencyError); }); + it('copies whitelisted properties', () => { + const e = new Error.StripeError({ + charge: 'foo', + unknown_prop: 'bar', + }); + expect(e).to.have.property('charge', 'foo'); + expect(e).not.to.have.property('unknown_prop', 'bar'); + expect(e).not.to.have.property('decline_code', 'xyzzy'); + }); + it('Pulls in headers', () => { const headers = {'Request-Id': '123'}; const e = Error.StripeError.generate({