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

Properly handle API errors with unknown error types #1357

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Error.js
Expand Up @@ -49,7 +49,7 @@ class StripeError extends Error {
case 'invalid_grant':
return new StripeInvalidGrantError(rawStripeError);
default:
return new GenericError('Generic', 'Unknown Error');
return new StripeUnknownError(rawStripeError);
}
}
}
Expand Down Expand Up @@ -122,6 +122,11 @@ class StripeIdempotencyError extends StripeError {}
*/
class StripeInvalidGrantError extends StripeError {}

/**
* Any other error from Stripe not specifically captured above
*/
class StripeUnknownError extends StripeError {}

module.exports.generate = StripeError.generate;
module.exports.StripeError = StripeError;
module.exports.StripeCardError = StripeCardError;
Expand All @@ -134,3 +139,4 @@ module.exports.StripeConnectionError = StripeConnectionError;
module.exports.StripeSignatureVerificationError = StripeSignatureVerificationError;
module.exports.StripeIdempotencyError = StripeIdempotencyError;
module.exports.StripeInvalidGrantError = StripeInvalidGrantError;
module.exports.StripeUnknownError = StripeUnknownError;
3 changes: 3 additions & 0 deletions test/Error.spec.js
Expand Up @@ -20,6 +20,9 @@ describe('Error', () => {
expect(
Error.StripeError.generate({type: 'idempotency_error'})
).to.be.instanceOf(Error.StripeIdempotencyError);
expect(
Error.StripeError.generate({type: 'weird_error'})
).to.be.instanceOf(Error.StripeUnknownError);
});

it('copies whitelisted properties', () => {
Expand Down