Skip to content

Commit

Permalink
Move sections on REST API exceptions 2 levels up
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Jul 13, 2022
1 parent 3badc47 commit eea793b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
43 changes: 21 additions & 22 deletions src/docs/asciidoc/web/webflux.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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]]
Expand All @@ -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]




Expand Down Expand Up @@ -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]]
Expand Down
41 changes: 21 additions & 20 deletions src/docs/asciidoc/web/webmvc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]]
Expand Down

0 comments on commit eea793b

Please sign in to comment.