Maps a raw Stripe OAuth error to a specific typed StripeError subclass based on the error type, enabling precise error handling.
export const generateOAuthError = (
rawStripeError: StripeRawError
): StripeError => {
const oauthType = rawStripeError.type;
switch (oauthType) {
case 'invalid_grant':
return new StripeInvalidGrantError(rawStripeError);
case 'invalid_client':
return new StripeInvalidClientError(rawStripeError);
case 'invalid_request':
return new StripeOAuthInvalidRequestError(rawStripeError);
case 'invalid_scope':
return new StripeInvalidScopeError(rawStripeError);
case 'unsupported_grant_type':
return new StripeUnsupportedGrantTypeError(rawStripeError);
case 'unsupported_response_type':
return new StripeUnsupportedResponseTypeError(rawStripeError);
default:
return new StripeOAuthError(rawStripeError);
}
};
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key