> ## Documentation Index
> Fetch the complete documentation index at: https://primer.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PrimerError

> The error type for payment and checkout failures, where errors arrive, and the error IDs the React Native layer raises.

> [!WARNING]
>
> Primer Checkout React Native SDK is currently in **beta** (v3.0.0-beta.1).
> The API is subject to change before the stable release.

`PrimerError` describes a payment or checkout failure. Every error has an `errorId` to branch on and a `description` to log. Errors usually carry a `diagnosticsId` to share with Primer support.

## Definition

Import the type with `import type { PrimerError } from '@primer-io/react-native'`. The block below shows the shape of the type, not code to copy.

```tsx theme={"dark"}
class PrimerError extends Error {
  errorId: string;
  errorCode?: string;
  description: string;
  recoverySuggestion?: string;
  diagnosticsId?: string;
}
```

## Properties

| Field | Type | Description |
| - | - | - |
| `errorId` | `string` | Identifier of the error category, for example `payment-failed` for a declined payment. Use it to branch in code. |
| `description` | `string` | Error message for logs. In your own UI, show your own message. |
| `errorCode` | `string \| undefined` | A more specific failure code, when one is available. Some errors raised by the React Native layer set it, see [Errors raised by the React Native layer](#errors-raised-by-the-react-native-layer). |
| `recoverySuggestion` | `string \| undefined` | Suggested recovery action, when the SDK has one. |
| `diagnosticsId` | `string \| undefined` | Diagnostics ID of this occurrence. Log it and include it when you contact Primer support. |

## Where errors arrive

You never create a `PrimerError`. Primer Checkout delivers it through these channels:

| Channel | What arrives there |
| - | - |
| `usePrimerCheckout().paymentOutcome` | `{ status: 'error', error, data }` for a failed payment attempt once the checkout is ready. Read it first. See [`usePrimerCheckout`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout). |
| `onError` prop of [`PrimerCheckoutProvider`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/primer-checkout-provider) | `(error, checkoutData)` for errors such as a declined card, a 3DS failure or a network error. |
| `usePrimerCheckout().error` | Initialization failures, before `isReady` is `true`. |
| Rejected promises | Some actions reject instead, for example `retry()` from `usePrimerCheckout`, and `start()` of a payment method with its own native UI. `start()` also rejects when Google Pay or Apple Pay is not available. |

A shopper who cancels a payment method with its own UI, for example by closing the Apple Pay, Google Pay or PayPal sheet, produces `errorId` `payment-cancelled`. To treat a cancel differently from a failure, check `errorId`.

### Reading an initialization error

Read the ID and message of an initialization error from `usePrimerCheckout().error`:

```tsx theme={"dark"}
import { Text } from 'react-native';
import { usePrimerCheckout } from '@primer-io/react-native';

type InitError = { errorId?: string; code?: string; description?: string; message?: string };

export function CheckoutInitError() {
  const { error } = usePrimerCheckout();
  if (!error) return null;

  const e = error as InitError;
  const id = e.errorId ?? e.code;
  const message = e.description ?? e.message;
  console.warn(`Checkout init failed [${id}]: ${message}`);

  return <Text>We couldn't load the checkout. Try again later.</Text>;
}
```

To recover from an initialization error, start a new session with a new `clientToken`, or remount `PrimerCheckoutProvider`.

## Handling payment errors

Watch `paymentOutcome` to catch every failed attempt.

```tsx theme={"dark"}
import { useEffect, type ReactNode } from 'react';
import { PrimerCheckoutProvider, usePrimerCheckout } from '@primer-io/react-native';
import type { PrimerError } from '@primer-io/react-native';

function logPrimerError(error: PrimerError, paymentId?: string) {
  console.warn(`[${error.errorId}] ${error.description}`, {
    diagnosticsId: error.diagnosticsId,
    errorCode: error.errorCode,
    paymentId,
  });
}

function PaymentErrorLogger() {
  const { paymentOutcome } = usePrimerCheckout();

  useEffect(() => {
    if (paymentOutcome?.status === 'error') {
      logPrimerError(paymentOutcome.error, paymentOutcome.data?.payment?.id);
    }
  }, [paymentOutcome]);

  return null;
}

export function Checkout({ clientToken, children }: { clientToken: string; children: ReactNode }) {
  return (
    <PrimerCheckoutProvider clientToken={clientToken}>
      <PaymentErrorLogger />
      {children}
    </PrimerCheckoutProvider>
  );
}
```

> [!TIP]
>
> When you contact Primer support about a failure, include the `diagnosticsId`. It identifies the exact occurrence in Primer's logs.

## Errors raised by the React Native layer

These are other error IDs you can see in `paymentOutcome` and the other channels in [Where errors arrive](#where-errors-arrive).

| `errorId` | When |
| - | - |
| `google-pay-unavailable` | Google Pay is started where it is not available. `errorCode` is the same as `errorId`. |
| `apple-pay-unavailable` | Apple Pay is started where it is not available. `errorCode` is the same as `errorId`. |
| `native-ui-start-failed` | A payment method with its own native UI failed to start. |
| `bank-selection-start-failed` | A bank selection payment method failed to start. |
| `klarna-start-failed` | The Klarna session failed to start. |
| `klarna-return-url-missing` | Android: a Klarna payment category is selected while `settings.paymentMethodOptions.klarnaOptions.returnIntentUrl` is not set. |
| `stripe-ach-unavailable` | The native SDK did not provide a Stripe ACH component. |
| `stripe-ach-start-failed` | Stripe ACH failed to start. |
| `stripe-ach-submit-failed` | Submitting the Stripe ACH details failed. |
| `stripe-ach-mandate-config` | The Stripe ACH mandate step was reached without `stripeOptions.mandateData.merchantName` or `fullMandateText`. `errorCode` is the same as `errorId`. |
| `stripe-ach-mandate-failed` | Accepting the Stripe ACH mandate failed. |
| `stripe-ach-decline-failed` | Declining the Stripe ACH mandate failed. |
| `additional-info-unhandled` | The native SDK sent additional payment information and `settings.headlessUniversalCheckoutCallbacks.onCheckoutAdditionalInfo` is not set. `errorCode` is the same as `errorId`. |
| `retry-unavailable` | `retry()` is called with nothing to retry. When the last outcome is an error, `retry()` rejects with that error instead. |
| `NO_ACTIVE_CARD_FORM` | `selectNetwork()` from [`usePrimerCardNetworkSelection`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-networks) is called while no card form is active. |
| `primer-rn-sdk` | Initialization: the native SDK's start result has no `availablePaymentMethods` list. `description` is "Failed to find availablePaymentMethods" and `recoverySuggestion` is "Create another client session". |

The `*-start-failed`, `*-submit-failed`, `*-mandate-failed` and `*-decline-failed` IDs wrap a failure that was not a `PrimerError`, such as a rejected native call. Their `description` is the original error's message. When the underlying failure is already a `PrimerError`, it arrives unchanged, with its own `errorId`.

The native bridges of the React Native SDK raise errors with their own IDs too, for example `native-ios`, `native-bridge` and `native-android`. They arrive through the same channels as errors from the native SDK, see [Where errors arrive](#where-errors-arrive). Branch on `errorId` and log `description`.

## See also

> [card] [usePrimerCheckout](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout.md)
>
> `paymentOutcome`, `error` and `retry()`

> [card] [Handle the payment result](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/guides/handle-payment-result.md)
>
> Success, pending and failure end to end

> [card] [Checkout data](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/common/checkout-data.md)
>
> `CheckoutData`, `PaymentOutcome` and the client session

> [card] [PrimerSettings](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/common/primer-settings.md)
>
> Settings behind several of these errors


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.