Problem Statement
Describe how you implement global exception handling in a Spring Boot REST API and what you return to clients.
Explanation
Use @ControllerAdvice with @ExceptionHandler methods to map exceptions to structured error responses. Return a stable JSON envelope with fields like timestamp, error code, message, and correlation ID. Map domain errors to 4xx with actionable messages; map unexpected faults to 5xx with a generic message and a trace ID. Always log server-side with the cause and context; never leak sensitive details in responses.
Practice Sets
This question appears in the following practice sets: