Error responses
Error response format and common error scenarios
Kashier returns more than one error shape. Business-logic errors use the standard envelope below. Authentication, schema, and validation errors return their own flat shapes instead. Branch your error handling on the HTTP status code first, then on which keys are present.
Standard error envelope (operational errors)
Most business-logic errors — invalid merchant configuration, invalid request objects, and similar — use a shared envelope:
{
"error": {
"cause": string // The technical cause of the error
},
"messages": {
"en": string, // English error message
"ar": string // Arabic error message
},
"status": "FAILURE" // Always "FAILURE" for this envelope
}Not every error uses this envelope
Authentication, authorization, schema, and request-validation failures return a flat { "message": ... }, an { "error": ... } string, or a { "more_info": [...] } array — with no messages object and no status field. Do not require status to be present before treating a non-2xx response as an error.
Common error scenarios
Invalid merchant ID
Returned when the merchant identifier is missing, malformed, or not recognised:
{
"error": {
"cause": "The request object is invalid"
},
"messages": {
"en": "Invalid merchant ID",
"ar": "Invalid merchant ID"
},
"status": "FAILURE"
}Troubleshooting authentication and permission errors
| Status | What to check |
|---|---|
| 400 | The request is invalid — check the headers and parameters you sent. |
| 401 or 403 | The credential, its permissions, or the calling IP is not allowed. Check the key's status, mode, permissions and IP allow-list. |
For details, see Authentication and Secret keys. Check the key's status, mode, IP allow-list and permissions. For payouts, see Allow-list your IP address.
Validation errors (400)
Validation errors come in two shapes. Check which one you're looking at before parsing.
Schema validation
Requests that fail request-schema validation (missing or malformed fields at the schema level) return only a list of the individual violations:
{
"more_info": [
{ "message": "should have required property 'amount'" }
]
}| Field | Type | Meaning |
|---|---|---|
more_info | array | The individual schema validation errors that were found. |
HTTP status: 400. There is no message, messages, or status key on this shape.
Field-level (body/query/param) validation
Most other input validation — required fields, format checks on individual body, query, or param values — returns a flat, localized message instead:
{
"message": "merchant ID is required"
}| Field | Type | Meaning |
|---|---|---|
message | string | The first validation error found, localized based on your request's language header. |
HTTP status: 400. Only the first error is returned even when several fields are invalid, so fix and re-send rather than expecting the full list.
Non-operational / unknown errors
An unexpected server-side failure does not use the envelope. It returns a flat message only:
{
"message": "Internal server error"
}A temporary service outage surfaces here rather than through the standard envelope.
Live-mode-only routes
Some routes only operate in live mode and reject calls made with test credentials.
Duplicate / conflicting records (409)
Returned when a request would create a record whose unique field already exists — for example reusing an invoice number, a category name, or a payment-request reference for the same merchant:
{
"status": 409,
"message": "The invoice number has already been used. Please enter another invoice number.",
"code": "DUPLICATE_KEY_ERROR"
}Match on code: "DUPLICATE_KEY_ERROR" rather than on the message text, which varies by the conflicting field:
| Conflicting field(s) | Message |
|---|---|
| Invoice reference | The invoice number has already been used. Please enter another invoice number. |
| Category name (slug) | The category name has already been used. Please enter another category name. |
merchantId + referenceId (payment requests) | A payment request with merchantId "..." and referenceId "..." already exists. |
| Any other duplicate key | A duplicate key error occurred. Please check your input and try again. |
Retrying a 409 with the same payload will fail again. Change the conflicting value or treat the existing record as the result.
Other errors return 400 with a message.
Quick reference by source
The top-level keys differ by error type — some responses use error.cause / messages / status, others use a flat message, an error string, or a more_info array. Branch your client error handling on the HTTP status code together with whichever of these keys is present in the body.
| Error source | HTTP status | Top-level keys |
|---|---|---|
| Operational / business-logic error | varies | error.cause, messages.{en,ar}, status: "FAILURE" |
| Non-operational / unexpected error | varies | message |
| Schema validation | 400 | more_info[] |
| Field-level validation | 400 | message |
| Authentication or permission failure | 401 or 403 | message (or error, message) |
| Invalid request | 400 | message or error |
| Live-mode-only route called with test credentials | 403 | message |
| Duplicate key / conflicting record | 409 | status, message, code: "DUPLICATE_KEY_ERROR" |
Best practices
- Treat any non-2xx HTTP status as an error. Do not rely on a
statusfield being present — several error paths omit it - Read the message from
messages.enwhen present, and fall back to the flatmessageorerrorkey, then tomore_info - Handle both English and Arabic messages appropriately based on your user's locale
- Pay special attention to the
error.causefield for debugging purposes - For authorization errors, verify your API key, your hash generation process, and the secret key's status, mode, IP allow-list and permissions
- Match 409 conflicts on
code: "DUPLICATE_KEY_ERROR"and do not blind-retry them - In live mode, ensure your account has the necessary credentials configured for each operation