Error Messages That Are Safe to Show and Still Useful to Debug¶
An API's error message has two readers. One is the caller, who may be anyone: a shopper's browser, a partner's
server, someone probing for a way in. The other is the engineer who has to fix the problem. What helps the second
often helps the wrong kind of first: which access rule refused the request, which account a key belongs to, what an
internal service answered. So most APIs answer Access denied. and nothing more. It is safe, and it leaves the
people building on the API guessing. They are the API's first customers.
A safe response with a link¶
ObjectsGrid now keeps both. The error response stays as safe as it was, and its instance, the member
RFC 9457 defines for "this occurrence", is the URL of the error's details:
{
"code": "ACCESS_DENIED",
"status": 401,
"detail": "You are not authorized to retrieve this object.",
"instance": "https://apis.objectsgrid.com/errordetails/01JF8Q2M7XK4T9B3W6Y5N0R1ZC",
"traceId": "4bf92f3577b34da6a3ce929d0e0e4736"
}
Behind the link is an ErrorDetail: what went wrong inside, such as no rule of policy version 3 allows retrieve on Offer for service account sa-42, tagged role=reporting, with the request's method, path and caller. Never its body, header values or IP address. Your administrators read it; your policy can let your developers too. The account that got the error can't, so a leaked key learns nothing more than before.
One id for one request¶
Error details are kept 90 days. Support often starts from a trace id rather than a link, so a request's details are found by its trace id too, the id every response already carries. They aren't searchable: that keeps them cheap to store, in a bucket of their own, apart from your business objects.
The same for your API¶
If your API answers its callers with generic errors too, it can store what went wrong in ObjectsGrid and return the URL, with your own codes from your error catalog. See Error details.