Add docs on error handling in REST scenarios

This commit is contained in:
Rossen Stoyanchev
2016-10-13 13:56:40 -04:00
parent 71201e1a43
commit e3ecf012f9

View File

@@ -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