> For the complete documentation index, see [llms.txt](https://docs.jgopay.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jgopay.com/english/errors.md). Agents can also search and read this documentation through its [MCP server](https://docs.jgopay.com/~gitbook/mcp).

# Error Handling

## Error Response Format

All errors follow a consistent format:

```json
{
  "status": "error",
  "error": "ERROR_CODE",
  "message": "Human-readable error message"
}
```

| Field     | Type   | Description                 |
| --------- | ------ | --------------------------- |
| `status`  | string | Always `"error"`            |
| `error`   | string | Machine-readable error code |
| `message` | string | Human-readable description  |

## Error Codes

### Authentication Errors

| Code                  | HTTP Status | Description                                                                       |
| --------------------- | ----------- | --------------------------------------------------------------------------------- |
| `UNAUTHORIZED`        | 401         | Missing or invalid access token                                                   |
| `TOKEN_EXPIRED`       | 401         | Access token has expired — request a new one                                      |
| `INVALID_CREDENTIALS` | 401         | Invalid `merchant_id` or `api_key`                                                |
| `INVALID_SIGNATURE`   | 401         | Signed request rejected — bad HMAC, timestamp outside ±5 min, or unknown merchant |
| `MERCHANT_DISABLED`   | 403         | Merchant account is disabled                                                      |
| `MERCHANT_LOCKED`     | 403         | Merchant account is locked                                                        |
| `DEPOSITS_DISABLED`   | 403         | Deposits are currently disabled for this merchant (withdrawals unaffected)        |

### Validation Errors

| Code                       | HTTP Status | Description                                                                                                                                       |
| -------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `VALIDATION_ERROR`         | 400         | One or more fields failed validation                                                                                                              |
| `INVALID_AMOUNT`           | 400         | Amount is outside the allowed range                                                                                                               |
| `DUPLICATE_REFERENCE`      | 409         | `reference_id` has already been used                                                                                                              |
| `MISSING_PROVIDER_CHANNEL` | 400         | `BANK_TRANSFER` without `metadata.provider_channel_id` — see [Payment Methods](https://docs.jgopay.com/english/payment-methods.md#fpx-bank-codes) |
| `INVALID_PROVIDER_CHANNEL` | 400         | `provider_channel_id` not in the allowed list                                                                                                     |

### Withdrawal Errors

| Code                | HTTP Status | Description                                                                              |
| ------------------- | ----------- | ---------------------------------------------------------------------------------------- |
| `INVALID_AMOUNT`    | 400         | Withdrawal amount outside 50.00 – 50,000.00 MYR                                          |
| `INVALID_BANK_CODE` | 400         | Bank code not supported. See [Bank Codes](https://docs.jgopay.com/english/bank-codes.md) |

### Rate Limiting

| Code           | HTTP Status | Description                                           |
| -------------- | ----------- | ----------------------------------------------------- |
| `RATE_LIMITED` | 429         | Too many requests — slow down and retry after a delay |

The 429 response includes a `Retry-After` header (in seconds). See [Rate Limiting](https://docs.jgopay.com/english/rate-limiting.md) for limits per endpoint and recommended backoff strategy.

### Gateway Errors

| Code                   | HTTP Status | Description                            |
| ---------------------- | ----------- | -------------------------------------- |
| `NO_GATEWAY_AVAILABLE` | 503         | No active gateway for this method      |
| `GATEWAY_ERROR`        | 502         | The upstream gateway returned an error |
| `GATEWAY_TIMEOUT`      | 504         | The upstream gateway did not respond   |

## Validation Rules (MYR)

```json
{
  "status": "error",
  "error": "VALIDATION_ERROR",
  "message": "reference_id must contain only alphanumeric characters (a-z, A-Z, 0-9)"
}
```

| Validation                     | Rule                                                          |
| ------------------------------ | ------------------------------------------------------------- |
| `reference_id`                 | Alphanumeric only — no spaces, hyphens, or special characters |
| `amount`                       | Up to 2 decimal places                                        |
| `amount` range                 | 5 – 50,000 MYR                                                |
| `metadata.provider_channel_id` | Required for `BANK_TRANSFER`                                  |

## Handling Errors

### Recommended Approach

```
1. Check HTTP status code
2. Parse the error response body
3. Use the `error` code for programmatic handling
4. Log the `message` for debugging
5. Display a user-friendly message to your customer
```

### Retry Guidance

| Error Code             | Retryable? | Action                         |
| ---------------------- | ---------- | ------------------------------ |
| `VALIDATION_ERROR`     | No         | Fix the request parameters     |
| `INVALID_AMOUNT`       | No         | Adjust the amount              |
| `DUPLICATE_REFERENCE`  | No         | Use a different `reference_id` |
| `UNAUTHORIZED`         | No         | Re-authenticate                |
| `TOKEN_EXPIRED`        | Yes        | Get a new token, then retry    |
| `NO_GATEWAY_AVAILABLE` | Yes        | Retry after a delay            |
| `GATEWAY_ERROR`        | Yes        | Retry after a delay            |
| `GATEWAY_TIMEOUT`      | Yes        | Retry after a delay            |
| `RATE_LIMITED`         | Yes        | Wait and retry after a delay   |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.jgopay.com/english/errors.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
