Errors, retries and limits
Every method except track() throws an ApiError when the platform answers with an error.
Handling errors
import { ApiError } from 'nahnu-analytics-sdk';
try {
await stats.sites.upsert(website.id, { name, domains, client: user.id });
} catch (e) {
if (e instanceof ApiError) {
console.error(e.status, e.code, e.message);
}
throw e;
} | Status | Means | Do |
|---|---|---|
| 401 | The key is wrong | Check NAHNU_ANALYTICS_KEY |
| 403 | Not a platform key | Make one with Can: Platform |
| 404 | No such client or site, or no Nahnu Analytics at that address | Check the ref, or NAHNU_ANALYTICS_URL |
| 422 | A field is not valid | The message names it |
| 429 | Over 20,000 requests an hour | Wait for X-RateLimit-Reset |
| 5xx | The platform had a problem | Retried for you when safe |
Safe by design#
track()never throws. A stats hiccup can’t break a checkout or a signup: it returnsfalseand passes the error toonError.- Retries: after a network error, a 429 or a 5xx, the client tries again up to
retriestimes (default 2), honouringRetry-After(up to 10 seconds), otherwise waiting half a second, then two. It only retries what can’t double anything: reads, updates, deletes, and events that all have anid. - Duplicates: the same event
idwithin three days counts once, so a webhook sent again isn’t a second sale.fromStripeandfromShopifyset it for you. - Rate limits: every answer has
X-RateLimit-Limit,X-RateLimit-RemainingandX-RateLimit-Reset. Fast reads from Cloudflare with a read token don’t count against them. - Timeouts: a request gives up after
timeoutmilliseconds (default 15,000).
Was this helpful?
Thanks for your feedback!
✓ Feedback received. Thank you!



