The basics
Handling errors
Every error has a stable code; branch on it, show the right message, and retry only what can be retried.
Errors are application/problem+json (RFC 7807) with a stable code. Branch on the code, never on the title or detail text, which can change. The error catalogue lists every code, what it means, what to do and whether retrying helps.
The flow at a glance
| # | Who | What happens |
|---|---|---|
| 1 | Your system | Reads the HTTP status and the code. |
| 2 | Your system | Retries only what the catalogue says passes; fixes the request otherwise. |
| 3 | Your system | Logs the X-Request-ID header of every failed call, for support. |
1. Read the problem
Your system.
Every error answer looks like this. detail explains this case; validation problems add an errors list with each field.
Response
{
"type": "about:blank",
"title": "Deposit refused",
"status": 422,
"code": "deposit_refused",
"detail": "the reference lookup has expired"
}
2. Decide whether to retry
Your system.
4xxmeans the request must change: fix it, or tell the user. Retrying the same request gives the same answer.429and503pass: wait for theRetry-Afterheader, then retry.5xxand timeouts: retry the same request with the sameIdempotency-Key(see Retrying safely).421 wrong_region: your tenant is served in another region; the answer names its base URL. Send the request there.
3. Tell support what failed
Your team.
Every answer carries an X-Request-ID header. Keep it with failed calls: it is how support finds your request.
Errors that matter here
Every error is application/problem+json with a stable code; branch on the code, not the message. The full list is in the error catalogue.
| Error | When | What to do |
|---|---|---|
400 invalid_request | The request is malformed or a field is out of range. | Fix the field the |
401 unauthorized | No key, or a key that does not work. | Check the key. |
403 insufficient_scope | The key lacks a scope. | Use a key with the scope. |
404 not_found | Unknown, or not visible to this key's account or mode. | Check the ID and the key's mode. |
409 idempotency_key_reused | The key was used for a different request. | New operation, new key. |
421 wrong_region | The account is served in another region. | Resend to the base URL in the answer. |
429 rate_limited | Too many requests. | Wait for |
500 internal_error | An error on KulPay's side. | Retry with the same key; contact support with the |
Testing it
Send a request with a missing field and check your code shows the right message from the code. Send too many lookups in a minute to see 429 and your back-off.