From e3ecf012f909aa636dbf19f4eb986a2e84a00441 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 13 Oct 2016 13:56:40 -0400 Subject: [PATCH] Add docs on error handling in REST scenarios --- src/asciidoc/web-mvc.adoc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/asciidoc/web-mvc.adoc b/src/asciidoc/web-mvc.adoc index ccd5721b58..b7a12cbf32 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