Handling Errors Consistently

Handling errors consistently in a REST API: custom exceptions, @ExceptionHandler, @RestControllerAdvice, status codes and one error body.

  • 7 cards
  • 5 questions
  • About 7 min
  • Intermediate to Advanced
Share

Error handling in a REST API: making every failure come back to the client in the same, useful shape. An API that returns a stack trace on one endpoint and a bare 500 on another has not been designed; it has accumulated, and clients cannot rely on it. It covers custom exceptions, @ExceptionHandler, @RestControllerAdvice, choosing the status code, how Spring picks between two handlers, and what an error body should contain. It leaves out security errors in depth and error handling in reactive applications.

Contents

7 cardsnot started