Docs
← Back to site

Errors, retries and limits

1 min readUpdated November 11, 2026

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;
}
StatusMeansDo
401The key is wrongCheck NAHNU_ANALYTICS_KEY
403Not a platform keyMake one with Can: Platform
404No such client or site, or no Nahnu Analytics at that addressCheck the ref, or NAHNU_ANALYTICS_URL
422A field is not validThe message names it
429Over 20,000 requests an hourWait for X-RateLimit-Reset
5xxThe platform had a problemRetried for you when safe

Safe by design#

  • track() never throws. A stats hiccup can’t break a checkout or a signup: it returns false and passes the error to onError.
  • Retries: after a network error, a 429 or a 5xx, the client tries again up to retries times (default 2), honouring Retry-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 an id.
  • Duplicates: the same event id within three days counts once, so a webhook sent again isn’t a second sale. fromStripe and fromShopify set it for you.
  • Rate limits: every answer has X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. Fast reads from Cloudflare with a read token don’t count against them.
  • Timeouts: a request gives up after timeout milliseconds (default 15,000).

Was this helpful?