diff --git a/src/asciidoc/web-mvc.adoc b/src/asciidoc/web-mvc.adoc index ccd5721b581172e03cbc74e004ec2a6ef526eb99..b7a12cbf321ff4c5360ce4c02e695d444d409786 100644 --- a/src/asciidoc/web-mvc.adoc +++ b/src/asciidoc/web-mvc.adoc @@ -4053,6 +4053,29 @@ response and write error content with message converters. See the +[[mvc-ann-rest-exceptions]] +=== REST Controller Exception Handling + +An `@RestController` may use `@ExceptionHandler` methods that return a +`ResponseEntity` to provide both a response status and error details in the body +of the response. Such methods may also be added to `@ControllerAdvice` +classes for exception handling across a subset or all controllers. + +A common requirement is to include error details in the body of the response. +Spring does not automatically do this (although Spring Boot does) because the +representation of error details in the response body is application specific. + +Applications that wish to implement a global exception handling strategy with +error details in the response body should consider extending the abstract base +class `ResponseEntityExceptionHandler` which provides handling for the exceptions +that Spring MVC raises and provides hooks to customize the response body as +well as to handle other exceptions. Simply declare the extension class as a +Spring bean and annotate it with `@ControllerAdvice`. For more details see +See `ResponseEntityExceptionHandler`. + + + + [[mvc-ann-annotated-exceptions]] === Annotating Business Exceptions With @ResponseStatus