Error envelope
When a request fails, the CAIL Health API returns a non-2xx HTTP status and a JSON body describing the failure. Most errors share a common shape. A few categories of failure return a reduced shape, so a client should branch on the HTTP status code and read message, both of which are always available.
Standard error
The majority of errors use this shape:
Message
message is always present, and is either a single string or an array of strings.
For most failures it is a single human-readable string. For a request that fails field validation, it is an array with one entry per validation problem:
Always handle message as either type.
Error code
Some failures add a code field: a short, machine-readable label for the specific failure. When present, code is the most precise signal to branch on.
code is not present on every error, and error may be absent when code is present. Treat both as optional.
Reduced shapes
Two categories of failure return fewer fields.
Pathway execution errors return only message and code, with no statusCode or meta. Read the HTTP status from the response itself:
An unexpected server error returns only statusCode and message:
What to rely on
Field availability varies across these shapes, so build clients on the parts that do not vary:
- The HTTP status code of the response is always present and authoritative. Branch on it first.
messageis always present. Handle it as a string or an array of strings.code,error, andmetaare best-effort. Use them when present, but never require them.
Support traceability
When meta.requestId is present, it uniquely identifies the request. Log it, and include it in any support request so the team can locate the request and its server-side context.