Skip to content

Commit d092c92

Browse files
committed
Update README.md
1 parent c7386d2 commit d092c92

File tree

4 files changed

+81
-47
lines changed

4 files changed

+81
-47
lines changed

README.md

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,19 @@ compatible down to `3.0.0`. Integration with Spring Boot 4 (once its released) w
114114
}
115115
```
116116

117-
Overriding of build-in exceptions is performed by custom [`ExceptionMapping`][ExceptionMapping] and its implementations.
118-
These mappings are instantiated in [`ExceptionMappingConfiguration`][ExceptionMappingConfiguration] with
119-
`@ConditionalOnClass`, per appropriate exception. Therefore, if using this library with previous versions, mappings for
120-
exception classes that are not present in classpath are silently ignored.
121-
122-
Details on what exception responses are overwritten are located following `README.md` files:
123-
124-
- [`problem4j-spring-web/README.md`][problem4j-spring-web-readme],
125-
- [`problem4j-spring-webflux/README.md`][problem4j-spring-webflux-readme],
126-
- [`problem4j-spring-webmvc/README.md`][problem4j-spring-webmvc-readme].
117+
Details on library usability can be found in [`problem4j-spring-web/README.md`][problem4j-spring-web-readme].
127118

128119
While creating your own `@RestControllerAdvice`, make sure to position it with right `@Order`. In order for your custom
129120
implementation to work seamlessly, make sure to position it on at least **`Ordered.LOWEST_PRECEDENCE - 1`** (the lower
130121
the value, the higher the priority), as **`ExceptionAdvice`** covers the most generic **`Exception`** class.
131122

132-
| `@RestControllerAdvice` | covered exceptions | `@Order(...)` |
133-
|--------------------------------------|--------------------------------|----------------------------------|
134-
| `ProblemEnhancedExceptionHandler` | Spring's internal exceptions | `Ordered.LOWEST_PRECEDENCE - 10` |
135-
| `ProblemExceptionAdvice` | `ProblemException` | `Ordered.LOWEST_PRECEDENCE - 10` |
136-
| `ConstraintViolationExceptionAdvice` | `ConstraintViolationException` | `Ordered.LOWEST_PRECEDENCE - 10` |
137-
| `ExceptionAdvice` | `Exception` | `Ordered.LOWEST_PRECEDENCE` |
123+
| <center>covered exceptions</center> | <center>`@Order(...)`</center> |
124+
|-------------------------------------|----------------------------------|
125+
| Spring's internal exceptions | `Ordered.LOWEST_PRECEDENCE - 10` |
126+
| `ConstraintViolationException` | `Ordered.LOWEST_PRECEDENCE - 10` |
127+
| `DecodingException` | `Ordered.LOWEST_PRECEDENCE - 10` |
128+
| `ProblemException` | `Ordered.LOWEST_PRECEDENCE - 10` |
129+
| `Exception` | `Ordered.LOWEST_PRECEDENCE` |
138130

139131
## Configuration
140132

@@ -150,25 +142,17 @@ library and your application.
150142

151143
- [`problem4j-core`][problem4j-core] - Core library defining `Problem` model and `ProblemException`.
152144
- [`problem4j-jackson`][problem4j-jackson] - Jackson module for serializing and deserializing `Problem` objects.
153-
- [`problem4j-spring`][problem4j-spring] - Spring Web module extending `ResponseEntityExceptionHandler` for
154-
handling exceptions and returning `Problem` responses.
155-
156-
[ExceptionMapping]: problem4j-spring-web/src/main/java/io/github/malczuuu/problem4j/spring/web/mapping/ExceptionMapping.java
157-
158-
[ExceptionMappingConfiguration]: problem4j-spring-web/src/main/java/io/github/malczuuu/problem4j/spring/web/mapping/ExceptionMappingConfiguration.java
159-
160-
[problem4j-spring-web-readme]: problem4j-spring-web/README.md
161-
162-
[problem4j-spring-webflux-readme]: problem4j-spring-webflux/README.md
163-
164-
[problem4j-spring-webmvc-readme]: problem4j-spring-webmvc/README.md
145+
- [`problem4j-spring`][problem4j-spring] - Spring modules extending `ResponseEntityExceptionHandler` for handling
146+
exceptions and returning `Problem` responses.
165147

166148
[maven-central]: https://central.sonatype.com/artifact/io.github.malczuuu.problem4j/problem4j-spring-bom
167149

168150
[problem4j-core]: https://github.com/malczuuu/problem4j-core
169151

170152
[problem4j-spring]: https://github.com/malczuuu/problem4j-spring
171153

154+
[problem4j-spring-web-readme]: problem4j-spring-web/README.md
155+
172156
[problem4j-jackson]: https://github.com/malczuuu/problem4j-jackson
173157

174158
[rfc7807]: https://datatracker.ietf.org/doc/html/rfc7807

problem4j-spring-web/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ registers these mappings.
77
These error mappings to disallow leaking too much information to the client application. It more information is
88
necessary, feel free to override specific [`ExceptionMapping`][ExceptionMapping], register it as `@Serivce`,
99
`@Component` or `@Bean` and exclude specific nested[`ExceptionMappingConfiguration`][ExceptionMappingConfiguration]
10-
configuration class.
10+
configuration class with `@ConditionalOnClass`, per appropriate exception. Therefore, if using this library with
11+
previous versions, mappings for exception classes that are not present in classpath are silently ignored.
1112

1213
Overriding whole `ProblemEnhancedExceptionHandler` is not recommended, although such necessities are sometimes
1314
understandable.
@@ -74,8 +75,8 @@ or not. For `true` it will use value from `@RequestParam` (if able) (the same go
7475

7576
<table>
7677
<tr>
77-
<td align="center"><code>ConstraintViolationException</code></td>
78-
<td align="center"><code>MethodValidationException</code></td>
78+
<td style="text-align:center"><code>ConstraintViolationException</code></td>
79+
<td style="text-align:center"><code>MethodValidationException</code></td>
7980
</tr>
8081
<tr>
8182
<td><pre lang="json">

problem4j-spring-webflux/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,36 @@
22

33
This module extends `problem4j-spring-web` overrides of responses for many framework exceptions and produces structured
44
RFC 7807 `Problem` objects, with exceptions that are specific to `spring-webflux`.
5+
6+
## Main Test Scenarios
7+
8+
1. What happens if `@PathVariable`, `@RequestParam`, etc. is missing - [`MissingParameterTest`][MissingParameterTest]
9+
2. What happens if `@PathVariable`, etc. is invalid - [`ValidateParameterTest`][ValidateParameterTest]
10+
3. What happens if `@PathVariable`, etc. has incorrect type - [`TypeMismatchTest`][TypeMismatchTest]
11+
4. What happens if `@RequestPart` is malformed - [`MalformedMultipartTest`][MalformedMultipartTest]
12+
5. What happens if `@RequestBody` is invalid - [`ValidateRequestBodyTest`][ValidateRequestBodyTest]
13+
6. What happens if `Accept` is invalid - [`NotAcceptableTest`][NotAcceptableTest]
14+
7. What happens if `Content-Type` is invalid - [`UnsupportedMediaTypeTest`][UnsupportedMediaTypeTest]
15+
8. What happens if HTTP method (`GET`,`POST`, etc.) is invalid - [`MethodNotAllowedTest`][MethodNotAllowedTest]
16+
9. What happens if unknown endpoint (or resource) is accessed - [`NotFoundTest`][NotFoundTest]
17+
10. What happens if `ErrorResponseException` is thrown - [`ErrorResponseTest`][ErrorResponseTest]
18+
19+
[MissingParameterTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/MissingParameterTest.java
20+
21+
[ValidateParameterTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/ValidateParameterTest.java
22+
23+
[TypeMismatchTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/TypeMismatchTest.java
24+
25+
[MalformedMultipartTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/MalformedMultipartTest.java
26+
27+
[ValidateRequestBodyTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/ValidateRequestBodyTest.java
28+
29+
[NotAcceptableTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/NotAcceptableTest.java
30+
31+
[UnsupportedMediaTypeTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/UnsupportedMediaTypeTest.java
32+
33+
[MethodNotAllowedTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/MethodNotAllowedTest.java
34+
35+
[NotFoundTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/NotFoundTest.java
36+
37+
[ErrorResponseTest]: src/test/java/io/github/malczuuu/problem4j/spring/webflux/integration/ErrorResponseTest.java

problem4j-spring-webmvc/README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
This module extends `problem4j-spring-web` overrides of responses for many framework exceptions and produces structured
44
RFC 7807 `Problem` objects, with exceptions that are specific to `spring-webmvc`.
55

6-
## `NoHandlerFoundException`
6+
## Override `404 Not Found`
77

8-
What triggers it: DispatcherServlet could not find any handler (no matching controller) for the request (requires
9-
`throwExceptionIfNoHandlerFound=true`).
8+
- `NoHandlerFoundException`
9+
- `NoResourceFoundException`
1010

11-
Mapping: [`NoHandlerFoundMapping`][NoHandlerFoundMapping]
11+
Makes both `404 Not Found` responses exactly the same so information about what is a static resource and what is a
12+
controller never leaks.
1213

1314
```json
1415
{
@@ -17,20 +18,35 @@ Mapping: [`NoHandlerFoundMapping`][NoHandlerFoundMapping]
1718
}
1819
```
1920

20-
## `NoResourceFoundException`
21+
## Main Test Scenarios
2122

22-
What triggers it: Static resource handling (e.g. `ResourceHttpRequestHandler`) couldn't resolve the requested resource (
23-
Spring Boot 3.x when resource chain handling is enabled).
23+
1. What happens if `@PathVariable`, `@RequestParam`, etc. is missing - [`MissingParameterTest`][MissingParameterTest]
24+
2. What happens if `@PathVariable`, etc. is invalid - [`ValidateParameterTest`][ValidateParameterTest]
25+
3. What happens if `@PathVariable`, etc. has incorrect type - [`TypeMismatchTest`][TypeMismatchTest]
26+
4. What happens if `@RequestPart` is malformed - [`MalformedMultipartTest`][MalformedMultipartTest]
27+
5. What happens if `@RequestBody` is invalid - [`ValidateRequestBodyTest`][ValidateRequestBodyTest]
28+
6. What happens if `Accept` is invalid - [`NotAcceptableTest`][NotAcceptableTest]
29+
7. What happens if `Content-Type` is invalid - [`UnsupportedMediaTypeTest`][UnsupportedMediaTypeTest]
30+
8. What happens if HTTP method (`GET`,`POST`, etc.) is invalid - [`MethodNotAllowedTest`][MethodNotAllowedTest]
31+
9. What happens if unknown endpoint (or resource) is accessed - [`NotFoundTest`][NotFoundTest]
32+
10. What happens if `ErrorResponseException` is thrown - [`ErrorResponseTest`][ErrorResponseTest]
2433

25-
Mapping: [`NoResourceFoundMapping`][NoResourceFoundMapping]
34+
[MissingParameterTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/MissingParameterTest.java
2635

27-
```json
28-
{
29-
"status": 404,
30-
"title": "Not Found"
31-
}
32-
```
36+
[ValidateParameterTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/ValidateParameterTest.java
37+
38+
[TypeMismatchTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/TypeMismatchTest.java
39+
40+
[MalformedMultipartTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/MalformedMultipartTest.java
41+
42+
[ValidateRequestBodyTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/ValidateRequestBodyTest.java
43+
44+
[NotAcceptableTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/NotAcceptableTest.java
45+
46+
[UnsupportedMediaTypeTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/UnsupportedMediaTypeTest.java
47+
48+
[MethodNotAllowedTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/MethodNotAllowedTest.java
3349

34-
[NoHandlerFoundMapping]: src/main/java/io/github/malczuuu/problem4j/spring/webmvc/mapping/NoHandlerFoundMapping.java
50+
[NotFoundTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/NotFoundTest.java
3551

36-
[NoResourceFoundMapping]: src/main/java/io/github/malczuuu/problem4j/spring/webmvc/mapping/NoResourceFoundMapping.java
52+
[ErrorResponseTest]: src/test/java/io/github/malczuuu/problem4j/spring/webmvc/integration/ErrorResponseTest.java

0 commit comments

Comments
 (0)