Skip to content

Commit

Permalink
Export errors to allow typed access to them
Browse files Browse the repository at this point in the history
Exports the errors module and the types it contains as `stripe.errors`.
This allows users to match on an error with the `instanceof` operator
instead of having to match on the string generated by accessing an
object's `type`.

Fixes #457.
  • Loading branch information
brandur committed May 12, 2018
1 parent 5b3318a commit f0c611c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function Stripe(key, version) {
this.setApiKey(key);
this.setApiVersion(version);

this.errors = require('./Error.js');
this.webhooks = require('./Webhooks');
}

Expand Down
6 changes: 6 additions & 0 deletions test/flows.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,5 +515,11 @@ describe('Flows', function() {
done();
});
});

it('Exports errors as types', function() {
expect(new stripe.errors.StripeInvalidRequestError({
message: "error"
}).type).to.equal('StripeInvalidRequestError');
});
});
});

0 comments on commit f0c611c

Please sign in to comment.