@@ -4910,7 +4910,7 @@ and any `ErrorResponseException`, and renders an error response with a body.
4910
4910
[.small]#<<web-reactive.adoc#webflux-ann-rest-exceptions-render, WebFlux>>#
4911
4911
4912
4912
You can return `ProblemDetail` or `ErrorResponse` from any `@ExceptionHandler` or from
4913
- any `@RequestMapping` method to render an RFC 7807 response as follows:
4913
+ any `@RequestMapping` method to render an RFC 7807 response. This is processed as follows:
4914
4914
4915
4915
- The `status` property of `ProblemDetail` determines the HTTP status.
4916
4916
- The `instance` property of `ProblemDetail` is set from the current URL path, if not
@@ -4919,11 +4919,12 @@ already set.
4919
4919
"application/problem+json" over "application/json" when rendering a `ProblemDetail`,
4920
4920
and also falls back on it if no compatible media type is found.
4921
4921
4922
- To enable RFC 7807 responses for Spring MVC exceptions and for any
4922
+ To enable RFC 7807 responses for Spring WebFlux exceptions and for any
4923
4923
`ErrorResponseException`, extend `ResponseEntityExceptionHandler` and declare it as an
4924
4924
<<mvc-ann-controller-advice,@ControllerAdvice>> in Spring configuration. The handler
4925
- obtains HTTP status, headers, and error details from each exception and prepares a
4926
- `ResponseEntity`.
4925
+ has an `@ExceptionHandler` method that handles any `ErrorResponse` exception, which
4926
+ includes all built-in web exceptions. You can add more exception handling methods, and
4927
+ use a protected method to map any exception to a `ProblemDetail`.
4927
4928
4928
4929
4929
4930
@@ -4940,7 +4941,7 @@ response, and likewise any unknown property during deserialization is inserted i
4940
4941
this `Map`.
4941
4942
4942
4943
You can also extend `ProblemDetail` to add dedicated non-standard properties.
4943
- The copy constructor in `ProblemDetail` allows a sub-class to make it easy to be created
4944
+ The copy constructor in `ProblemDetail` allows a subclass to make it easy to be created
4944
4945
from an existing `ProblemDetail`. This could be done centrally, e.g. from an
4945
4946
`@ControllerAdvice` such as `ResponseEntityExceptionHandler` that re-creates the
4946
4947
`ProblemDetail` of an exception into a subclass with the additional non-standard fields.
@@ -4954,20 +4955,18 @@ from an existing `ProblemDetail`. This could be done centrally, e.g. from an
4954
4955
It is a common requirement to internationalize error response details, and good practice
4955
4956
to customize the problem details for Spring MVC exceptions. This is supported as follows:
4956
4957
4957
- - Each `ErrorResponse` exposes a message code and message code arguments to resolve the
4958
- problem "detail" field through a <<core.adoc#context-functionality-messagesource,MessageSource>>.
4958
+ - Each `ErrorResponse` exposes a message code and arguments to resolve the "detail" field
4959
+ through a <<core.adoc#context-functionality-messagesource,MessageSource>>.
4959
4960
The actual message code value is parameterized with placeholders, e.g.
4960
4961
`"HTTP method {0} not supported"` to be expanded from the arguments.
4961
- - `ResponseEntityExceptionHandler` uses the message code and the message arguments
4962
- to resolve the problem "detail" field.
4963
- - Lower level exceptions that cannot implement `ErrorResponse`, e.g. `TypeMismatchException`,
4964
- have their problem detail, including message code and arguments set in
4965
- `ResponseEntityExceptionHandler`.
4962
+ - Each `ErrorResponse` also exposes a message code to resolve the "title" field.
4963
+ - `ResponseEntityExceptionHandler` uses the message code and arguments to resolve the
4964
+ "detail" and the "title" fields.
4966
4965
4967
- Message codes default to " problemDetail." + the fully qualified exception class name. Some
4968
- exceptions may expose additional message codes in which case a suffix is added to
4969
- the default message code. The table below lists message arguments and codes for Spring
4970
- MVC exceptions:
4966
+ By default, the message code for the "detail" field is " problemDetail." + the fully
4967
+ qualified exception class name. Some exceptions may expose additional message codes in
4968
+ which case a suffix is added to the default message code. The table below lists message
4969
+ arguments and codes for Spring MVC exceptions:
4971
4970
4972
4971
[[mvc-ann-rest-exceptions-codes]]
4973
4972
[cols="1,1,2", options="header"]
@@ -5054,6 +5053,9 @@ MVC exceptions:
5054
5053
5055
5054
|===
5056
5055
5056
+ By default, the message code for the "title" field is "problemDetail.title." + the fully
5057
+ qualified exception class name.
5058
+
5057
5059
5058
5060
5059
5061
[[mvc-ann-rest-exceptions-client]]
0 commit comments