1- # Built-in Spring Exception Mappings
1+ # Mapping exceptions to ` application/problem+json ` responses
2+
3+ 1 . [ Overview] ( #overview )
4+ 2 . [ Returning response bodies from custom exceptions] ( #returning-response-bodies-from-custom-exceptions )
5+ 1 . [ Extending ` ProblemException ` ] ( #extending-problemexception )
6+ 2 . [ Annotating ` @ProblemMapping ` ] ( #annotating-problemmapping )
7+ 3 . [ Validation] ( #validation )
8+ 4 . [ Occurrences of ` TypeMismatchException ` ] ( #occurrences-of-typemismatchexception )
9+ 5 . [ Occurrences of ` ErrorResponseException ` ] ( #occurrences-of-errorresponseexception )
10+ 6 . [ General HTTP Stuff] ( #general-http-stuff )
11+
12+ ## Overview
213
314This module overrides Spring Web's default (often minimal or plain-text) responses for many framework exceptions and
415produces structured RFC 7807 ` Problem ` objects. [ ` ExceptionMappingConfiguration ` ] [ ExceptionMappingConfiguration ]
@@ -67,7 +78,7 @@ To extract values from target exception, it's possible to use placeholders for i
6778
6879``` java
6980/**
70- * <pre >{@code
81+ * <pre >{@code
7182 * {
7283 * "type": "https://example.com/errors/invalid-request",
7384 * "title": "Invalid Request",
@@ -127,7 +138,9 @@ property `spring.validation.method.adapt-constraint-violations` to `true`. Enabl
127138not rely on raw ` ConstraintViolationException ` , but rather on ` MethodValidationException ` , which contains more details
128139about validated element.
129140
130- Let's say we have following ` @RestController ` , where ` idx ` query param has different Java parameter name.
141+ Let's say we have following ` @RestController ` , where ` customerId ` query param has different Java parameter name (its
142+ ` String customerIdParam ` ). We would like to have ` customerId ` in our response body as potential API clients do not have
143+ knowledge about internal technologies used by backend.
131144
132145``` java
133146@Validated
@@ -175,6 +188,8 @@ or not. For `true` it will use value from `@RequestParam` (if able) (the same go
175188</tr >
176189</table >
177190
191+ * Note* that this is not build-in behaviour. It was implemented in [ ` MethodValidationMapping ` ] [ MethodValidationMapping ] .
192+
178193## Occurrences of ` TypeMismatchException `
179194
180195Triggered for example when trying to pass ` String ` value into ` @RequestParam("param") Integer param ` .
@@ -240,7 +255,7 @@ Example:
240255 }
241256 ```
2422575 . If passing request that's too large by configuration, service will write following response. Note that reason phrase
243- for ` 413 ` was changed into ` Content Too Large ` in [ RFC 9110 §15.5.14] [ rfc9110-15.5.4 ] .
258+ for ` 413 ` was changed into ` Content Too Large ` in [ RFC 9110 §15.5.14] [ rfc9110-15.5.4 ] .
244259 ``` json
245260 {
246261 "status" : 413 ,
@@ -253,3 +268,5 @@ Example:
253268[ ExceptionMapping ] : src/main/java/io/github/malczuuu/problem4j/spring/web/mapping/ExceptionMapping.java
254269
255270[ ExceptionMappingConfiguration ] : src/main/java/io/github/malczuuu/problem4j/spring/web/mapping/ExceptionMappingConfiguration.java
271+
272+ [ MethodValidationMapping ] : src/main/java/io/github/malczuuu/problem4j/spring/web/mapping/MethodValidationMapping.java
0 commit comments