The Creditra Backend wraps every JSON response in a consistent envelope so
that clients can branch on the presence of an error field without having
to know endpoint-specific shapes.
- Exactly one of
data/erroris non-null at any time. erroris always a human-readable string. Structured error details (codes, fields) are intentionally omitted from this generic envelope; endpoint-specific error structures, where they exist, live insidedataon4xxresponses.- For
5xxresponses, the envelope deliberately hides internal error messages. Clients should treaterroras opaque text and rely on the HTTP status for retry logic.
Use ok(res, payload, status?) and fail(res, error, status?) from
src/utils/response.ts instead of building envelopes inline. This keeps
internal details (stack traces, SQL errors) from leaking into 5xx
responses by default.