Good error docs prevent support tickets. Here are Agata's stable codes and copy-paste examples.
Error shape#
| Field | When | Client use |
|---|---|---|
error.code | Whenever there is an AppError | UX / i18n branch |
error.message | Almost always | Readable fallback (may not be i18n) |
error.limit_key | Plan limits | Map to billing copy |
error.limit | Plan limits | Show the cap |
error.required_plan | Plan limits | Upgrade CTA |
error.resolution | Plan limits | upgrade_plan or purchase_addon |
error.addon_key | Expandable limits | extra_members or ai_credit_packs |
request_id | Always | Support / logs |
Go type: dto.ErrorResponse + apperrors.AppError.
Stable codes#
Source: apps/api/internal/shared/apperrors/errors.go.
| code | Typical HTTP | Meaning | What to do |
| --- | --- | --- |
| UNAUTHORIZED | 401 | No identity / invalid secret | Re-login; check the server secret |
| FORBIDDEN | 403 | No permission (role, section, membership) | Do not retry the same way; access UI |
| NOT_FOUND | 404 | Resource missing or not visible | Empty state / soft-delete |
| VALIDATION_ERROR | 400 | Invalid input | Show form fields |
| DUPLICATE_RESOURCE | 409 | Conflict / duplicate | Uniqueness message |
| PLAN_LIMIT | 402/403/429 depending on the route* | Plan cap | Upsell + limit_key |
| RATE_LIMIT_EXCEEDED | 429 | HTTP rate limit | Backoff + Retry-After; do not confuse with PLAN_LIMIT |
| INTERNAL_SERVER_ERROR | 500 | Unexpected failure | Generic toast + log request_id |
*The exact HTTP status is set by the handler; the code is the stable signal for the TypeScript client (isStructuredApiErr).
Rate limit (reads and writes)#
The API rate-limits authenticated requests per user with fixed counters in Upstash Redis (separate buckets):
| Type | Methods | Per minute | Per hour | Env |
|---|---|---|---|---|
| Writes | POST / PATCH / PUT / DELETE | 90 | 1200 | RATE_LIMIT_WRITES_PER_* |
| Reads | GET / HEAD | 300 | 5000 | RATE_LIMIT_READS_PER_* |
- Enabled when
UPSTASH_REDIS_REST_URL+UPSTASH_REDIS_REST_TOKENare configured (orRATE_LIMIT_ENABLED=true). Force off:RATE_LIMIT_ENABLED=false. - Health and
/api/internal/*(cron) do not count. - If Redis fails or is not configured, the middleware fails open (lets the request through) and logs a warn.
- The response includes a
Retry-Afterheader (seconds until the window ends).
This is not a plan cap: PLAN_LIMIT is billing/entitlements; RATE_LIMIT_EXCEEDED is anti-abuse.
Examples by scenario#
401 — secret or session#
or
Action: refresh the Better Auth session; on the server, do not cache dead tokens.
400 — validation#
Action: highlight the field; do not retry blindly.
Plan limit#
Known customer-facing keys (apps/app/shared/utils/plan-limits/keys.ts plus owner cap):
members_per_profileprofiles_per_owneragent_credits_per_month
Action: if resolution is upgrade_plan, open the upsell with the required plan.
If it is purchase_addon, send the owner to Billing → Extras using addon_key;
members without permission must contact the owner.
For example, when Agent credits run out on a paid plan:
429 — rate limit#
Header: Retry-After: <seconds>.
Action: toast with the mapped message; wait / backoff. Do not retry in a loop (e.g. autosave).
404#
409 — conflict / document version#
On rich text, a stale expectedVersion can return a conflict. Reload the document (GET …/document) and retry with the new version.
Handling in TypeScript (monorepo pattern)#
Client best practices#
- Always log
request_idon 5xx errors. - Do not show stacks or SQL messages to the user.
- Distinguish
PLAN_LIMITfromVALIDATION_ERROR(different UX). - Retry only on idempotent 429/5xx, with backoff.
- Do not retry 401/403 in a loop — break the session or show access denied.
Request ID#
The middleware assigns or propagates:
Include it in bug reports: “create transaction failed, request_id=…”.