Card 06/ 07
Practice: Designing an Error Response Body
Beyond the status code, what a client and a support engineer need in order to act.
An error response body is what a client reads to find out what went wrong and what to do about it. Suppose RideNotFoundException is handled in one @RestControllerAdvice class, a single place whose handlers apply to every controller. Decide which fields its response body should contain so that a client can act on it, and a support engineer can find the failure in the server's logs, before you open a suggestion.
See a reasonable shape
{
"timestamp": "2026-09-15T10:30:45",
"status": 404,
"error": "Ride Not Found",
"message": "Ride not found with id: 100",
"path": "/rides/100"
}Enough to log, enough to display, and enough to match against a server-side log by time and path. The status is repeated in the body so that a client which only parses the body still knows what happened.
Spring 6 also supports ProblemDetail, a standard error format (RFC 9457) with fields such as status, title and detail. Returning it from every handler gives the API a shape that client libraries already understand.
← → move through sections and cards