Browse Source

Move sections on REST API exceptions 2 levels up

See gh-28438
pull/28821/head
rstoyanchev 3 years ago
parent
commit
eea793be98
  1. 43
      src/docs/asciidoc/web/webflux.adoc
  2. 41
      src/docs/asciidoc/web/webmvc.adoc

43
src/docs/asciidoc/web/webflux.adoc

@ -3410,26 +3410,6 @@ Support for `@ExceptionHandler` methods in Spring WebFlux is provided by the @@ -3410,26 +3410,6 @@ Support for `@ExceptionHandler` methods in Spring WebFlux is provided by the
for more detail.
[[webflux-ann-rest-exceptions]]
==== REST API exceptions
[.small]#<<web.adoc#mvc-ann-rest-exceptions, Web MVC>>#
A common requirement for REST services is to include error details in the body of the
response. The Spring Framework does not automatically do so, because the representation
of error details in the response body is application-specific. However, a
`@RestController` can use `@ExceptionHandler` methods with a `ResponseEntity` return
value to set the status and the body of the response. Such methods can also be declared
in `@ControllerAdvice` classes to apply them globally.
Applications that implement global exception handling with error details in the response
body should consider extending
{api-spring-framework}/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.html[`ResponseEntityExceptionHandler`],
which provides handling for exceptions that Spring MVC raises and provides hooks to
customize the response body. To make use of this, create a subclass of
`ResponseEntityExceptionHandler`, annotate it with `@ControllerAdvice`, override the
necessary methods, and declare it as a Spring bean.
[[webflux-ann-controller-advice]]
@ -3511,6 +3491,26 @@ include::web-uris.adoc[leveloffset=+2] @@ -3511,6 +3491,26 @@ include::web-uris.adoc[leveloffset=+2]
include::webflux-cors.adoc[leveloffset=+1]
[[webflux-ann-rest-exceptions]]
== REST API exceptions
[.small]#<<web.adoc#mvc-ann-rest-exceptions, Web MVC>>#
A common requirement for REST services is to include error details in the body of the
response. The Spring Framework does not automatically do so, because the representation
of error details in the response body is application-specific. However, a
`@RestController` can use `@ExceptionHandler` methods with a `ResponseEntity` return
value to set the status and the body of the response. Such methods can also be declared
in `@ControllerAdvice` classes to apply them globally.
Applications that implement global exception handling with error details in the response
body should consider extending
{api-spring-framework}/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.html[`ResponseEntityExceptionHandler`],
which provides handling for exceptions that Spring MVC raises and provides hooks to
customize the response body. To make use of this, create a subclass of
`ResponseEntityExceptionHandler`, annotate it with `@ControllerAdvice`, override the
necessary methods, and declare it as a Spring bean.
[[webflux-web-security]]
@ -3526,8 +3526,6 @@ reference documentation, including: @@ -3526,8 +3526,6 @@ reference documentation, including:
* {doc-spring-security}/features/exploits/csrf.html#csrf-protection[CSRF protection]
* {doc-spring-security}/features/exploits/headers.html[Security Response Headers]
include::webflux-view.adoc[leveloffset=+1]
@ -3700,6 +3698,7 @@ You should serve static resources with a `Cache-Control` and conditional respons @@ -3700,6 +3698,7 @@ You should serve static resources with a `Cache-Control` and conditional respons
for optimal performance. See the section on configuring <<webflux-config-static-resources>>.
include::webflux-view.adoc[leveloffset=+1]
[[webflux-config]]

41
src/docs/asciidoc/web/webmvc.adoc

@ -4016,26 +4016,6 @@ level, <<mvc-exceptionhandlers, HandlerExceptionResolver>> mechanism. @@ -4016,26 +4016,6 @@ level, <<mvc-exceptionhandlers, HandlerExceptionResolver>> mechanism.
|===
[[mvc-ann-rest-exceptions]]
==== REST API exceptions
[.small]#<<web-reactive.adoc#webflux-ann-rest-exceptions, WebFlux>>#
A common requirement for REST services is to include error details in the body of the
response. The Spring Framework does not automatically do this because the representation
of error details in the response body is application-specific. However, a
`@RestController` may use `@ExceptionHandler` methods with a `ResponseEntity` return
value to set the status and the body of the response. Such methods can also be declared
in `@ControllerAdvice` classes to apply them globally.
Applications that implement global exception handling with error details in the response
body should consider extending
{api-spring-framework}/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.html[`ResponseEntityExceptionHandler`],
which provides handling for exceptions that Spring MVC raises and provides hooks to
customize the response body. To make use of this, create a subclass of
`ResponseEntityExceptionHandler`, annotate it with `@ControllerAdvice`, override the
necessary methods, and declare it as a Spring bean.
[[mvc-ann-controller-advice]]
=== Controller Advice
@ -4835,9 +4815,30 @@ Note that you can also set the default timeout value on a `DeferredResult`, @@ -4835,9 +4815,30 @@ Note that you can also set the default timeout value on a `DeferredResult`,
a `ResponseBodyEmitter`, and an `SseEmitter`. For a `Callable`, you can use
`WebAsyncTask` to provide a timeout value.
include::webmvc-cors.adoc[leveloffset=+1]
[[mvc-ann-rest-exceptions]]
== REST API exceptions
[.small]#<<web-reactive.adoc#webflux-ann-rest-exceptions, WebFlux>>#
A common requirement for REST services is to include error details in the body of the
response. The Spring Framework does not automatically do this because the representation
of error details in the response body is application-specific. However, a
`@RestController` may use `@ExceptionHandler` methods with a `ResponseEntity` return
value to set the status and the body of the response. Such methods can also be declared
in `@ControllerAdvice` classes to apply them globally.
Applications that implement global exception handling with error details in the response
body should consider extending
{api-spring-framework}/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.html[`ResponseEntityExceptionHandler`],
which provides handling for exceptions that Spring MVC raises and provides hooks to
customize the response body. To make use of this, create a subclass of
`ResponseEntityExceptionHandler`, annotate it with `@ControllerAdvice`, override the
necessary methods, and declare it as a Spring bean.
[[mvc-web-security]]

Loading…
Cancel
Save