Skip to the workspace
Pebellslearn by building
Robust Endpoints  ›  Capstone Project

Error Handling and Problem Details

Error Handling 15 minA good error pairs the correct HTTP status for machines with a specific, actionable message for humans in one consistent shape, such as the Problem Details format, without leaking internals.

api design / Error Handling and Problem Details

Explore each scene at your own pace.

01 · The rule

The rule

Error Handling and Problem Details

A developer's integration fails at 2 a.m. with {"error": "Something went wrong"}. They cannot tell if their input was wrong, their token expired, or BookNook is down. Good error responses are the part of an API people remember most, because they arrive at the worst moment.

The rule

Right status for machines, clear detail for humans, one shape for all.

Every error answers three questions:

  1. What kind of failure? The HTTP status code, so clients and tools can react without parsing text.
  2. What exactly went wrong, and how do I fix it? A human-readable message, specific enough to act on.
  3. Where do I look it up? A stable error type and, ideally, a request id for support and logs.

Instead of inventing a format, use the standard Problem Details format, first defined in RFC 7807 and updated by RFC 9457. It has its own media type, application/problem+json, and a few standard fields:

HTTP/1.1 409 Conflict
Content-Type: application/problem+json

{
  "type": "https://api.booknook.example/problems/book-unavailable",
  "title": "Book is not available",
  "status": 409,
  "detail": "Book 42 is on loan until 2026-10-09.",
  "instance": "/v1/loans",
  "available_from": "2026-10-09"
}
  • type: a URI naming the kind of problem; the same for every occurrence, and it can point to documentation.
  • title: a short, fixed summary of that type.
  • status: the HTTP status, repeated for convenience.
  • detail: what went wrong this time.
  • instance: which request or resource it concerns.

You may add extension fields, like available_from above, or an errors list for validation failures that names each bad field.

What errors must not contain: stack traces, SQL, internal hostnames or secrets. Log those on the server under a request id, and give the caller only the id.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.