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

# Handle API Errors and Recover Failed Requests

> Read the Razorpay error response, decide whether to fix, retry or offer another payment method, and know what to show the customer and what to log.

Available in
🇮🇳 India

This page brings together the error-handling rules for Razorpay APIs: how to read a failure response, what to do for each class of error, what to show the customer, what to log and how to recover a request that timed out. It is for developers who call Razorpay APIs from their server or handle payment failures from Checkout. To look up a specific error reason, use the [product error lists](#product-error-lists).

## Read the error response

When a request fails, Razorpay returns a JSON error response with the relevant error parameters. The error response contains `code`, `description`, `field`, `source`, `step`, `reason` and `metadata`.

| Parameter | What it tells you |
| - | - |
| `code` | Type of the error. |
| `description` | Descriptive text about the error. |
| `field` | Name of the parameter in the API request that caused the error. |
| `source` | The point of failure in the operation. |
| `step` | The stage where the transaction failure occurred. The stages can vary depending on the payment method. |
| `reason` | The exact error reason. It can be handled programmatically. |
| `metadata` | Additional information about the request, such as `payment_id` and `order_id`. |

The `source` parameter tells you where the error originated and who needs to act. The values and the action for each are listed in the [List of Errors](https://razorpay.com/docs/errors/payments/list.md). The values of `source` and `step` for each payment method are in [Payment Method Error Parameters](https://razorpay.com/docs/errors/payments/payment-methods-error-parameters.md).

See the sample error response and the full parameter descriptions in [About Errors](https://razorpay.com/docs/errors#error-structure).

## What to do for each error class

For payments APIs, read `error.code`, `reason`, `source` and `step` before you decide what to do next. For RazorpayX payouts, see [RazorpayX payouts](#razorpayx-payouts).

| `error.code` | Meaning | Do this |
| - | - | - |
| `BAD_REQUEST_ERROR` | Something in the request or the customer's input. | Do not retry as-is. Fix the request, or ask the customer to try again or use another method. |
| `GATEWAY_ERROR` | The bank or network failed. | Offer another method. Check downtimes. |
| `SERVER_ERROR` | Razorpay failed. | Retry with back-off. Before you retry, make the call safe to repeat as described in [Recover a request that timed out](#recover-a-request-that-timed-out). |

Follow these rules when you build the handling:

* Do not retry a bad request as-is. The same `BAD_REQUEST_ERROR` fails again and again.
* For a `BAD_REQUEST_ERROR` with the reason `input_validation_failed`, check the `description` and `field` parameters to find what to correct in the request.
* Branch your logic on `reason` and `source`, not on `description`. If you match on `description`, a wording change breaks your handling.

For the HTTP status code returned with each kind of failure, see [HTTPS Status Codes](https://razorpay.com/docs/api/understand.md#https-status-codes). For requests that are rate limited, see [Rate Limiting](https://razorpay.com/docs/api/understand.md#rate-limiting).

## What to show the customer

Show the customer the `description`, and give them a meaningful next step based on the payment step and the failure reason. For example, when the `reason` is `invalid_otp`, you can notify the customer and ask them to retry the payment with the correct OTP.

On Standard Checkout, the behaviour depends on how you integrated:

| Integration | On payment failure |
| - | - |
| Checkout with handler function | The customer is notified about the payment failure and asked to retry the payment. The `payment.failed` event returns the error object to your page, including `code`, `description`, `source`, `step`, `reason` and the `order_id` and `payment_id` in `metadata`. |
| Checkout with callback URL | The checkout is displayed again so that the customer can retry the payment. |

See [Handle Payment Success and Failure](https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/integration-steps.md) in the Standard Checkout integration steps for the failure handling code.

> [!WARNING]
>
> **Watch Out!**
>
> A failed payment signature check is not an error to recover from. It indicates a potentially fraudulent or tampered payment. Reject the order entirely: do not fulfil it, do not retry and do not treat it as a genuine payment.

## What to log

Log `reason`, `source` and `step` for support and dashboards.

Group failures by `reason` to spot a bank or method that is failing. Without per-reason monitoring, a failing bank can go unnoticed for hours.

## Recover a request that timed out

Every call you might retry must be safe to repeat.

| Call | If it times out | Safe because |
| - | - | - |
| Create order | Retry with the same `receipt`. Create the order with `unique_receipt: true` so that a retried create returns the same order instead of a duplicate. | Your receipt identifies the purchase. |
| Create payment | Fetch the order's payments first, then retry on the same order. Retry only if no payment is in progress or captured. | A paid order cannot take a second successful payment. |
| Create refund | Retry with the same `X-Refund-Idempotency` header. The key must be at least 10 characters. | Same key, same refund. |
| Webhook received twice | Ignore the repeat. Check the `x-razorpay-event-id` header. | The same event can arrive more than once. |

To fetch the payments made against an order, use the [Fetch Payments for an Order](https://razorpay.com/docs/api/orders/fetch-payments.md) API.

Fetching the order's payments before you retry a payment assumes that you retry on the same order. Check that this matches your integration if you create a new order for each attempt. See [Retries and Idempotency](https://razorpay.com/docs/payments/payment-gateway/s2s-integration/test-s2s/best-practices/retries-and-idempotency.md) for the scenarios to test.

### RazorpayX payouts

When you retry a payout request after a 5XX error:

1. Use the same idempotency key as the original request.
2. Send the same request body. A different request body for the same idempotency key is rejected.

Razorpay guarantees the payout will not be processed twice if it was already completed. If the payout was created by the first request, the retried request returns the created payout details along with its current status.

See [Handling 5XX Errors](https://razorpay.com/docs/errors/x.md#handling-5xx-errors) for the recommended retry schedule and how to check the payout status, and [Make a Request Idempotent](https://razorpay.com/docs/api/x/payout-idempotency/make-request.md) to add the idempotency key.

## Product error lists

Use these pages to look up an error reason and its next steps.

| Product | Error list |
| - | - |
| Common API errors | [Common Errors](https://razorpay.com/docs/errors/common.md) |
| Payments | [List of Errors](https://razorpay.com/docs/errors/payments/list.md) |
| Payments, by method | [Payment Method Error Parameters](https://razorpay.com/docs/errors/payments/payment-methods-error-parameters.md) |
| Cards | [Cards Error Codes](https://razorpay.com/docs/errors/payments/cards.md) |
| S2S integration | [Error Index](https://razorpay.com/docs/payments/payment-gateway/s2s-integration/test-s2s/error-index.md) |
| Standard Checkout | [Troubleshooting & FAQs](https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/troubleshooting-faqs.md) |
| RazorpayX | [Error Types](https://razorpay.com/docs/errors/x.md), [Contact Error Codes](https://razorpay.com/docs/errors/x/contacts.md), [Fund Account Error Codes](https://razorpay.com/docs/errors/x/fund-account.md) and [Payout Status Details](https://razorpay.com/docs/errors/x/payout-status-details.md) |
| POS | [Razorpay POS Error Codes and Troubleshooting](https://razorpay.com/docs/errors/pos.md) |
| BBPS | [List of BBPS Errors](https://razorpay.com/docs/errors/bbps/list) |

## Related Information

* [About Errors](https://razorpay.com/docs/errors)
* [Understand Razorpay APIs](https://razorpay.com/docs/api/understand.md)
* [Best Practices](https://razorpay.com/docs/api/best-practices.md)
* [Error Handling for S2S Integration](https://razorpay.com/docs/payments/payment-gateway/s2s-integration/test-s2s/best-practices/error-handling.md)
* [Retries and Idempotency](https://razorpay.com/docs/payments/payment-gateway/s2s-integration/test-s2s/best-practices/retries-and-idempotency.md)
* [Standard Checkout Integration Steps](https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/integration-steps.md)
