Skip to content

Error Format — problem+json

The status code says which kind of error; the body should say what specifically went wrong, in a shape that is identical across every endpoint. Inventing a new error shape per endpoint is a tax clients pay forever.

There is a standard for exactly this: Problem Details for HTTP APIs (RFC 9457), served as application/problem+json. Its members:

  • type — a URI identifying the problem kind (a stable, documentable key).
  • title — a short, human-readable summary (stable per type).
  • status — the HTTP status code, repeated in the body.
  • detail — a human-readable explanation specific to this occurrence.
  • instance — a URI for this particular occurrence (often the request path).
  • plus any extension members you need (e.g. an errors array).
{
"type": "https://api.example.com/problems/out-of-stock",
"title": "Item is out of stock",
"status": 409,
"detail": "Only 2 units of SKU-123 remain; you requested 5.",
"instance": "/orders/8821",
"available": 2
}
JavaScript
What media type does RFC 9457 use for error bodies?
What is the purpose of the `type` member?
When a problem needs no special category, `type` should be: