2 min read
The envelope
{
"error": {
"type": "validation",
"code": "invalid_amount",
"message": "amount must be between 1000 and 150000",
"request_id": "req_44be1c"
}
}type is a broad family (validation, rate_limit, auth, not_found, server). code is a stable machine string. message is human-readable and may change — never branch on it.
One handler for all of them
async function call(url, init) {
const res = await fetch(url, init);
const body = await res.json().catch(() => ({}));
if (!res.ok) {
const e = body.error || {};
console.error(`Credicorp ${res.status} ${e.code} (${e.request_id})`);
throw new ApiError(res.status, e.code, e.message, e.request_id);
}
return body;
}
Map status to behaviour
- 400 validation — fix the request, show the field error.
- 404 not_found — the id/key does not exist; render a fallback.
- 409 conflict — usually an idempotency clash; you already have the result.
- 429 rate_limited — back off and retry (see the rate-limit recipe).
- 5xx / 503 server/unavailable — retry with back-off, then degrade gracefully.
Frequently asked questions
Should I branch on the message text?
No. The message is for humans and can change wording at any time. Branch only on code, which is a stable contract.
What do I do with request_id?
Log it with every failed call. When you contact support, quoting the request_id lets the team find your exact request in seconds.
Related reading

Quickstart: handle rate limits on the public API
The public ring is rate-limited, and a 429 tells you exactly when to try again. Read the RateLimit-Remaining…
Read →
Quickstart: add timeouts and retries to a Node.js API client
A production API client needs a timeout and a retry policy. In Node, an AbortController bounds every request…
Read →
Quickstart: use idempotency keys on write requests
An Idempotency-Key header makes a POST safe to retry. Generate one UUID per logical operation, send it with…
Read →Funding for UK limited companies
Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.