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

Conversation

praboud-stripe
Copy link
Contributor

When the API returns an error of a type which isn't explicitly enumerated, StripeError.generate tries to return a GenericError. However, that class doesn't exist - it was deleted as part of the refactor in #672. This causes stripe-node to return an especially confusing error - it complains about the undefined GenericError class, instead of telling us anything useful about the actual error.

This patch defines a fallback subclass of StripeError to use in these cases. (As a bonus, this means that the default error rendering will also contain the error message from the API, instead of a fixed Unknown Error string.)

AFAICT, the only way it was possible to hit this branch is to get the oauth flow to return weird errors. Since this is served from connect.stripe.com instead of api.stripe.com, it can return non-standard error types. It's not clear to me whether it's worth creating new error classes for these cases - for now, I've just fixed the type error.

@CLAassistant
Copy link

CLAassistant commented Feb 25, 2022

CLA assistant check
All committers have signed the CLA.

@richardm-stripe
Copy link
Contributor

Thank you @praboud-stripe, this looks good to me!

@richardm-stripe richardm-stripe merged commit 2a1a35b into stripe:master Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants