Skip to content

Commit eea793b

Browse files
committed
Move sections on REST API exceptions 2 levels up
See gh-28438
1 parent 3badc47 commit eea793b

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

src/docs/asciidoc/web/webflux.adoc

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,26 +3410,6 @@ Support for `@ExceptionHandler` methods in Spring WebFlux is provided by the
34103410
for more detail.
34113411

34123412

3413-
[[webflux-ann-rest-exceptions]]
3414-
==== REST API exceptions
3415-
[.small]#<<web.adoc#mvc-ann-rest-exceptions, Web MVC>>#
3416-
3417-
A common requirement for REST services is to include error details in the body of the
3418-
response. The Spring Framework does not automatically do so, because the representation
3419-
of error details in the response body is application-specific. However, a
3420-
`@RestController` can use `@ExceptionHandler` methods with a `ResponseEntity` return
3421-
value to set the status and the body of the response. Such methods can also be declared
3422-
in `@ControllerAdvice` classes to apply them globally.
3423-
3424-
Applications that implement global exception handling with error details in the response
3425-
body should consider extending
3426-
{api-spring-framework}/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.html[`ResponseEntityExceptionHandler`],
3427-
which provides handling for exceptions that Spring MVC raises and provides hooks to
3428-
customize the response body. To make use of this, create a subclass of
3429-
`ResponseEntityExceptionHandler`, annotate it with `@ControllerAdvice`, override the
3430-
necessary methods, and declare it as a Spring bean.
3431-
3432-
34333413

34343414

34353415
[[webflux-ann-controller-advice]]
@@ -3511,6 +3491,26 @@ include::web-uris.adoc[leveloffset=+2]
35113491
include::webflux-cors.adoc[leveloffset=+1]
35123492

35133493

3494+
[[webflux-ann-rest-exceptions]]
3495+
== REST API exceptions
3496+
[.small]#<<web.adoc#mvc-ann-rest-exceptions, Web MVC>>#
3497+
3498+
A common requirement for REST services is to include error details in the body of the
3499+
response. The Spring Framework does not automatically do so, because the representation
3500+
of error details in the response body is application-specific. However, a
3501+
`@RestController` can use `@ExceptionHandler` methods with a `ResponseEntity` return
3502+
value to set the status and the body of the response. Such methods can also be declared
3503+
in `@ControllerAdvice` classes to apply them globally.
3504+
3505+
Applications that implement global exception handling with error details in the response
3506+
body should consider extending
3507+
{api-spring-framework}/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.html[`ResponseEntityExceptionHandler`],
3508+
which provides handling for exceptions that Spring MVC raises and provides hooks to
3509+
customize the response body. To make use of this, create a subclass of
3510+
`ResponseEntityExceptionHandler`, annotate it with `@ControllerAdvice`, override the
3511+
necessary methods, and declare it as a Spring bean.
3512+
3513+
35143514

35153515

35163516
[[webflux-web-security]]
@@ -3526,8 +3526,6 @@ reference documentation, including:
35263526
* {doc-spring-security}/features/exploits/csrf.html#csrf-protection[CSRF protection]
35273527
* {doc-spring-security}/features/exploits/headers.html[Security Response Headers]
35283528

3529-
include::webflux-view.adoc[leveloffset=+1]
3530-
35313529

35323530

35333531

@@ -3700,6 +3698,7 @@ You should serve static resources with a `Cache-Control` and conditional respons
37003698
for optimal performance. See the section on configuring <<webflux-config-static-resources>>.
37013699

37023700

3701+
include::webflux-view.adoc[leveloffset=+1]
37033702

37043703

37053704
[[webflux-config]]

src/docs/asciidoc/web/webmvc.adoc

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4016,26 +4016,6 @@ level, <<mvc-exceptionhandlers, HandlerExceptionResolver>> mechanism.
40164016
|===
40174017

40184018

4019-
[[mvc-ann-rest-exceptions]]
4020-
==== REST API exceptions
4021-
[.small]#<<web-reactive.adoc#webflux-ann-rest-exceptions, WebFlux>>#
4022-
4023-
A common requirement for REST services is to include error details in the body of the
4024-
response. The Spring Framework does not automatically do this because the representation
4025-
of error details in the response body is application-specific. However, a
4026-
`@RestController` may use `@ExceptionHandler` methods with a `ResponseEntity` return
4027-
value to set the status and the body of the response. Such methods can also be declared
4028-
in `@ControllerAdvice` classes to apply them globally.
4029-
4030-
Applications that implement global exception handling with error details in the response
4031-
body should consider extending
4032-
{api-spring-framework}/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.html[`ResponseEntityExceptionHandler`],
4033-
which provides handling for exceptions that Spring MVC raises and provides hooks to
4034-
customize the response body. To make use of this, create a subclass of
4035-
`ResponseEntityExceptionHandler`, annotate it with `@ControllerAdvice`, override the
4036-
necessary methods, and declare it as a Spring bean.
4037-
4038-
40394019

40404020
[[mvc-ann-controller-advice]]
40414021
=== Controller Advice
@@ -4835,9 +4815,30 @@ Note that you can also set the default timeout value on a `DeferredResult`,
48354815
a `ResponseBodyEmitter`, and an `SseEmitter`. For a `Callable`, you can use
48364816
`WebAsyncTask` to provide a timeout value.
48374817

4818+
48384819
include::webmvc-cors.adoc[leveloffset=+1]
48394820

48404821

4822+
[[mvc-ann-rest-exceptions]]
4823+
== REST API exceptions
4824+
[.small]#<<web-reactive.adoc#webflux-ann-rest-exceptions, WebFlux>>#
4825+
4826+
A common requirement for REST services is to include error details in the body of the
4827+
response. The Spring Framework does not automatically do this because the representation
4828+
of error details in the response body is application-specific. However, a
4829+
`@RestController` may use `@ExceptionHandler` methods with a `ResponseEntity` return
4830+
value to set the status and the body of the response. Such methods can also be declared
4831+
in `@ControllerAdvice` classes to apply them globally.
4832+
4833+
Applications that implement global exception handling with error details in the response
4834+
body should consider extending
4835+
{api-spring-framework}/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.html[`ResponseEntityExceptionHandler`],
4836+
which provides handling for exceptions that Spring MVC raises and provides hooks to
4837+
customize the response body. To make use of this, create a subclass of
4838+
`ResponseEntityExceptionHandler`, annotate it with `@ControllerAdvice`, override the
4839+
necessary methods, and declare it as a Spring bean.
4840+
4841+
48414842

48424843

48434844
[[mvc-web-security]]

0 commit comments

Comments
 (0)