🔌API Error Response
Also known as Error Response, Problem Details, application/problem+json, RFC 9457
What an API sends back when a request fails. It gives a code and a reason.
Think of it like
Think of it like a note on a locked door. It says why you cannot get in and what to do next.
Example
Jack asks for order 42, which does not exist. The API answers 404 with the title Order not found.
Why it matters
Good errors tell the caller how to fix the problem, which saves hours of guessing.
Definition
Example code
json
{
"type": "https://example.com/errors/not-found",
"title": "Order not found",
"status": 404,
"detail": "No order has the number 42.",
"instance": "/orders/42"
}Common mistake
Key takeaways
- 1Right status code. 404, 400, 500 and so on.
- 2Say why. A body that explains it.
- 3Same shape. Every error looks alike.