Commit f8d8a53
committed
Give custom exceptions a @ResponseStatus fallback so unwritable-body errors resolve correctly
When a client sends an un-negotiable Accept (e.g. application/xml) on an error path, the
@ExceptionHandler runs and builds its JSON body, but the write fails with
HttpMediaTypeNotAcceptableException. Spring does not re-enter @ExceptionHandler resolution
for an exception raised inside exception handling, so the original ResourceNotFoundException
/ InsufficientStockException propagated to the container as a 500.
Spring's built-in exceptions implement ErrorResponse and self-resolve body-lessly in this
case; our custom RuntimeExceptions had no fallback. Annotating them with @ResponseStatus
lets ResponseStatusExceptionResolver answer with the right status (404 / 409) body-lessly.
The @ExceptionHandler still wins for normal requests, so the uniform {status,error,message}
body — and the recorded 63-case suite (all Accept: */*) — is unchanged.
Also drop handleNotAcceptable: it never fired (the write failure isn't re-entrant), and
success-path 406 is already produced by Spring's built-in negotiation.
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>1 parent 2a922d8 commit f8d8a53
3 files changed
Lines changed: 18 additions & 9 deletions
File tree
- spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/error
Lines changed: 0 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
113 | 112 | | |
114 | 113 | | |
115 | 114 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | 115 | | |
125 | 116 | | |
126 | 117 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
3 | 12 | | |
4 | 13 | | |
5 | 14 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
3 | 12 | | |
4 | 13 | | |
5 | 14 | | |
| |||
0 commit comments