Welcome to Nebutra Sailor Docs 🎉
ChangelogIntroductionLicensing
Help Center (External) ↗

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

StatusMeaning
200Success
201Created
204No content (e.g. DELETE)
400Bad request — invalid parameters
401Unauthorized — missing or invalid token
403Forbidden — token valid, but insufficient permissions
404Not found
409Conflict — duplicate resource or state conflict
422Unprocessable entity — validation error
429Rate limit exceeded
500Internal server error
503Service unavailable — dependency unhealthy

Error codes

These are the codes @nebutra/errors (packages/platform/errors) defines as ERROR_CODES:

CodeDescription
BAD_REQUESTRequest body or parameters are malformed
VALIDATION_ERROROne or more fields failed validation
UNAUTHORIZEDNo valid authentication token
FORBIDDENInsufficient permission for this action
NOT_FOUNDThe requested resource does not exist
CONFLICTA resource with this key already exists, or a state conflict
RATE_LIMITEDToo many requests in the time window
QUOTA_EXCEEDEDUsage quota exhausted
INTERNAL_ERRORUnexpected server error — contact support
SERVICE_UNAVAILABLEDependency (DB, cache) temporarily unavailable
EXTERNAL_SERVICE_ERRORAn upstream provider (AI, payments, email, …) failed
DATABASE_ERRORA database operation failed
TIMEOUTA downstream call exceeded its deadline
PAYMENT_REQUIREDAction requires an active paid plan
SUBSCRIPTION_EXPIREDThe tenant's subscription has lapsed
FEATURE_DISABLEDFeature flag is off for this tenant
TENANT_SUSPENDEDThe 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 error
  • user_id — which user made the request
  • request_id — correlated with API logs
  • route — which endpoint was called

Related

Rate Limits

How to handle 429 rate limit responses.

API Reference

Full error code reference.

How is this guide?

Edit on GitHub

Last updated on

On this page

Error envelope
HTTP status codes
Error codes
Validation errors
Error handling with @nebutra/errors
Idempotency
Error monitoring
Related