Skip to content

Commit

Permalink
Merge pull request #699 from stripe/richardm-more-fields-raw-error
Browse files Browse the repository at this point in the history
Add request-specific fields from raw error to top level error
  • Loading branch information
richardm-stripe authored Oct 8, 2019
2 parents bc3b1ae + 81521f0 commit f1b2149
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/Error.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit f1b2149

Please sign in to comment.