{ "error": "order_not_pending" }Some errors add fields next to error, such as required on insufficient_scope.
Status codes
| Status | Meaning |
|---|---|
200 / 201 |
Success (201 when something was created). |
202 |
Accepted: queued to run in the background (test events, resends). |
400 |
The request is malformed or fails validation. |
401 |
The API key is missing or invalid. |
403 |
The key can't do this (scope, route or plan). |
404 |
Not found, or it belongs to another business. |
409 |
Conflicts with the current state (e.g. paying an order that's already paid). |
422 |
Understood, but can't be processed (e.g. a variant that doesn't exist). |
429 |
Rate limited. |
5xx |
Something went wrong on our side. Safe to retry GET, PUT and DELETE. |
Validation errors
When the body or the query string doesn't match the endpoint's schema, the API answers 400 with the list of issues:
{
"success": false,
"error": {
"name": "ZodError",
"issues": [
{ "code": "too_small", "path": ["items"], "message": "Array must contain at least 1 element(s)" }
]
}
}The SDK turns this into a MallaValidationError with code: "validation_error" and the issues in details.issues.
Common error codes
| Status | error |
When |
|---|---|---|
| 404 | not_found |
The object doesn't exist in your business. |
| 409 | order_not_pending |
A payment link was requested for an order that isn't pending. |
| 409 | nothing_to_pay |
The order total is 0. |
| 409 | out_of_stock |
Not enough stock for an order line. |
| 409 | invalid_status_transition |
E.g. fulfilling an order that isn't paid. |
| 409 | phone_taken |
Another customer already has this phone. |
| 409 | code_taken |
Another discount already uses this code. |
| 409 | window_closed |
WhatsApp's 24-hour window to reply freely has closed. |
| 409 | too_many_endpoints |
Over 10 webhook endpoints. |
| 422 | invalid_items |
A variant doesn't exist or its product isn't active. |
| 422 | invalid_discount |
The discount code can't be used for this order. |
| 422 | invalid_events |
Unknown webhook event types. |
| 400 | invalid_url |
A webhook URL that isn't public https. |
| 403 | payments_not_enabled |
The business can't take payments yet (verification or payout account pending). |
Handling errors with the SDK
Every error is a MallaError with status, code and details; subclasses cover the common cases.
import { MallaConflictError, MallaError, MallaPermissionError } from '@malla/business'
try {
await malla.paymentLinks.create({ orderId })
}
catch (error) {
if (error instanceof MallaConflictError && error.code === 'order_not_pending')
return // already paid or cancelled
if (error instanceof MallaPermissionError)
throw new Error(`Grant ${error.required ?? 'access'} to this key`)
throw error
}