Errors
Errors answer with an HTTP status and JSON. Check the status first, then code where there is one, and show error to people: it’s written in plain words.
{ "error": "A client with this external_id already exists", "code": "external_id_taken" } Statuses#
| Status | Means | What to do |
|---|---|---|
400, 422 | Something in the request is wrong; error says what, like destination_url must be a full http:// or https:// address. | Fix the request. Don’t retry as is. |
401 | No key, or a wrong or revoked one. | Check the key and header. |
403 | The key can’t do this: read only, account paused, a plan limit (link_limit, click_limit) or a feature not on the plan. | Show error. Upgrading or a different key may help. |
404 | No such link, client or domain, or not yours. | Check the id or reference. |
409 | Already taken: an ending on that domain, an external_id, a domain. | Choose another value. |
429 | Too many requests for the key’s rate limit (rate_limited); wait the seconds it says. | Wait, then retry. |
503 | Something isn’t set up yet, like domains_not_set_up, or the database couldn’t be reached. | Retry after a few seconds; check setup if it persists. |
Codes you may want to handle#
| Code | Status | Meaning |
|---|---|---|
link_limit | 403 | The account has reached its link limit. |
click_limit | 403 | The account reached its monthly click limit; new links wait until the month resets. |
rate_limited | 429 | Too many requests this minute for this key. |
external_id_taken | 409 | Another client already has this external_id. |
domains_not_set_up | 503 | Domains over the API isn’t turned on. |
Retrying safely#
Retry only 429 and 503, with a growing wait between tries (for example 1, 2, 4 seconds). Other errors won’t change by retrying.
async function call(url, opts, tries = 3) {
for (let i = 0; i < tries; i++) {
const res = await fetch(url, opts);
if (res.status !== 429 && res.status !== 503) return res;
await new Promise(r => setTimeout(r, 1000 * 2 ** i));
}
throw new Error('Nahnu Links API is busy, try again later');
} Creating a link twice with the same ending is safe: the second call answers 409, not a duplicate link.


