Error Handling
Nebutra's error envelope format, error codes, and retry strategies.
Error envelope
All error responses from the Nebutra API use a consistent JSON envelope:
{
"success": false,
"error": {
"code": "NOT_FOUND",
"message": "Project proj_123 not found.",
"details": {
"resource": "Project",
"id": "proj_123"
},
"request_id": "req_2a8bXXXXXXXXX"
}
}Always log the request_id when reporting issues to support — it enables us to trace the exact request in our logs.
HTTP status codes
| Status | Meaning |
|---|---|
200 | Success |
201 | Created |
204 | No content (e.g. DELETE) |
400 | Bad request — invalid parameters |
401 | Unauthorized — missing or invalid token |
403 | Forbidden — token valid, but insufficient permissions |
404 | Not found |
409 | Conflict — duplicate resource or state conflict |
422 | Unprocessable entity — validation error |
429 | Rate limit exceeded |
500 | Internal server error |
503 | Service unavailable — dependency unhealthy |
Error codes
These are the codes @nebutra/errors (packages/platform/errors) defines as ERROR_CODES:
| Code | Description |
|---|---|
BAD_REQUEST | Request body or parameters are malformed |
VALIDATION_ERROR | One or more fields failed validation |
UNAUTHORIZED | No valid authentication token |
FORBIDDEN | Insufficient permission for this action |
NOT_FOUND | The requested resource does not exist |
CONFLICT | A resource with this key already exists, or a state conflict |
RATE_LIMITED | Too many requests in the time window |
QUOTA_EXCEEDED | Usage quota exhausted |
INTERNAL_ERROR | Unexpected server error — contact support |
SERVICE_UNAVAILABLE | Dependency (DB, cache) temporarily unavailable |
EXTERNAL_SERVICE_ERROR | An upstream provider (AI, payments, email, …) failed |
DATABASE_ERROR | A database operation failed |
TIMEOUT | A downstream call exceeded its deadline |
PAYMENT_REQUIRED | Action requires an active paid plan |
SUBSCRIPTION_EXPIRED | The tenant's subscription has lapsed |
FEATURE_DISABLED | Feature flag is off for this tenant |
TENANT_SUSPENDED | The tenant has been suspended |
Validation errors
Validation errors include field-level details:
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Validation failed for 2 fields.",
"details": {
"fields": [
{ "field": "email", "message": "Must be a valid email address" },
{ "field": "name", "message": "Required, must be at least 2 characters" }
]
}
}
}Error handling with @nebutra/errors
There's no client SDK — backends/gateway is the sole API surface, and route handlers throw a typed AppError:
import { AppError, ERROR_CODES } from "@nebutra/errors";
app.get("/api/v1/projects/:id", async (c) => {
const project = await getProject(c.req.param("id"));
if (!project) {
throw new AppError({
code: ERROR_CODES.NOT_FOUND,
message: `Project ${c.req.param("id")} not found.`,
statusCode: 404,
});
}
return c.json(project);
});On the caller side, treat the JSON envelope's error.code as the thing to branch on — there's no typed error class to instanceof-check against, since responses cross an HTTP boundary:
const res = await fetch("/api/v1/projects/proj_123");
const body = await res.json();
if (!body.success) {
if (body.error.code === "NOT_FOUND") return notFound();
if (body.error.code === "VALIDATION_ERROR") return { errors: body.error.details };
console.error(`[${body.error.code}] ${body.error.message} (request: ${body.error.request_id})`);
}Idempotency
Idempotency middleware deduplicates mutation endpoints (POST, PUT, DELETE) that could be retried — pass an idempotency key header on the request rather than a client-side option, since there's no SDK wrapping the call:
await fetch("/api/v1/invoices", {
method: "POST",
headers: { "Idempotency-Key": `invoice-${Date.now()}-${crypto.randomUUID()}` },
body: JSON.stringify({ amount: 9900, currency: "usd", orgId: "org_123" }),
});The same request with the same idempotency key within the configured window returns the original response instead of creating a duplicate resource.
Error monitoring
Nebutra ships with Sentry integration for server-side error tracking. Errors are automatically tagged with:
tenant_id— which org triggered the erroruser_id— which user made the requestrequest_id— correlated with API logsroute— which endpoint was called
Related
How is this guide?
Last updated on