Errors
API error envelope, error codes, validation error shape, and SDK error classes.
Updated 2026-10-11
Every error response uses the same envelope. The code field is stable across versions and safe to match against; the message field is human-friendly and may change.
Envelope
{
"error": {
"code": "validation_error",
"message": "Invalid request body",
"details": {
"fieldErrors": { "question": ["Too small: expected string to have >=1 characters"] },
"formErrors": []
}
}
}
code: machine-readable, stable, snake_casemessage: human-readable, may evolvedetails: optional structured context, such as field-level validation errors
Every response carries an X-Request-Id header. The SDK copies it to err.requestId; quote it when you contact support.
Common error codes
| Code | HTTP | When |
|---|---|---|
validation_error |
400 | Request body, query, or params failed validation |
invalid_json |
400 | Body was not valid JSON |
unauthorized |
401 | Missing or invalid API key, or the organization was not found |
forbidden |
403 | The key lacks a scope the route needs |
plan_required |
403 | The feature needs a higher plan; the error includes upgradeUrl |
plan_limit_exceeded |
403 | The organization hit a plan cap, such as questions or categories |
not_found |
404 | The resource does not exist or belongs to another organization |
conflict |
409 | The request conflicts with current state |
slug_conflict |
409 | No unique slug could be allocated; pass an explicit slug |
payload_too_large |
413 | Request body exceeds the size limit |
rate_limit_exceeded |
429 | Per-minute limit hit; wait for Retry-After seconds |
monthly_quota_exceeded |
429 | Monthly request quota used up; see Retry-After |
internal_error |
500 | Server-side failure; quote the X-Request-Id |
quota_unavailable |
503 | Usage metering is briefly unavailable; retry shortly |
Resource-specific codes are documented per endpoint.
Validation errors
Validated endpoints return field-level details from the schema:
{
"error": {
"code": "validation_error",
"message": "Invalid request body",
"details": {
"fieldErrors": { "answer": ["Too small: expected string to have >=1 characters"] },
"formErrors": []
}
}
}
fieldErrors keys map to your request body’s shape. formErrors carries issues that apply to the request as a whole.
SDK error classes
@faqapp/core throws typed error classes so you can handle each case explicitly:
import {
FAQAPIError,
FAQNetworkError,
FAQNotFoundError,
FAQRateLimitError,
FAQTimeoutError,
FAQValidationError
} from "@faqapp/core";
try {
await faq.questions.create({ question: "", answer: "" });
} catch (err) {
if (err instanceof FAQValidationError) {
console.error(err.errors);
} else if (err instanceof FAQNotFoundError) {
console.error("not found", err.requestId);
} else if (err instanceof FAQRateLimitError) {
await new Promise(resolve => setTimeout(resolve, (err.retryAfter ?? 1) * 1000));
} else if (err instanceof FAQAPIError) {
console.error(err.status, err.code, err.requestId);
} else if (err instanceof FAQNetworkError) {
console.error("network", err.message);
} else if (err instanceof FAQTimeoutError) {
console.error("timeout", err.message);
}
}
Best practices
- Match on
code, notmessage. Codes are stable; messages are not. - Log the
X-Request-Id. Quote it in any support email; we look up the exact request with it. - Backoff on 429. Use the
Retry-Aftervalue; exponential backoff for repeated failures. - Don’t show raw
messageto end users. Map codes to UI copy you control. - Treat network errors as different from API errors. A timeout is not a
500; retry strategy differs.