generateV2Error (Error)

stripe-node · payments, error-mapping, stripe-api, v2-endpoints, idempotency-handling

Maps raw Stripe API errors to typed error classes for V2 endpoints, handling idempotency, rate limits, and invalid fields before falling back to V1 error generation.

// 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 generateV2Error = (
  rawStripeError: StripeRawError
): StripeError => {
  switch (rawStripeError.type) {
    case 'idempotency_error':
      return new StripeIdempotencyError(rawStripeError);
    // switchCases: The beginning of the section generated from our OpenAPI spec
    case 'rate_limit':
      return new RateLimitError(rawStripeError);
    case 'temporary_session_expired':
      return new TemporarySessionExpiredError(rawStripeError);
    // switchCases: The end of the section generated from our OpenAPI spec
  }

  // Special handling for requests with missing required fields in V2 APIs.
  // invalid_field re

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

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

Get a free API key