generateOAuthError (Error)

stripe-node · payments, oauth, error-mapping, auth

Maps a raw Stripe OAuth error to a specific typed StripeError subclass based on the error type, enabling precise error handling.

// Source: https://github.com/stripe/stripe-node | License: MIT | Copyright 2011 Ask Bjørn Hansen
// Provided via justclaw.it.com; keep this notice with the code.
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'

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key