Handle specific reasons of HttpMessageNotReadableException
See original GitHub issueSomething like this
@ExceptionHandler
public ResponseEntity<Problem> onHttpMessageNotReadable(final HttpMessageNotReadableException e) throws Throwable {
final Throwable cause = e.getCause();
if (cause == null) {
return onException(e);
} else if (cause instanceof JsonParseException) {
return onParseException((JsonParseException) cause);
} else if (cause instanceof JsonMappingException) {
return onMappingException((JsonMappingException) cause);
} else {
...
}
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
java - @ExceptionHandler doesn't catch ... - Stack Overflow
You have to specify the class that the handler needs to handle. Like: @ExceptionHandler(HttpMessageNotReadableException.class).
Read more >Guide to Spring Boot REST API Error Handling - Toptal
I have a question on how to log the error in RestExceptionHandler to identify which API call cause the error. I think the...
Read more >Error Handling for REST with Spring
1. Restful API Error / Exception Design · The status represents HTTP status code. · error_code represents REST API specific error code. ·...
Read more >Additional Handling of Jackson Parsing and Mapping Errors
Common handling of JSON parsing/mapping exceptions. ... @ExceptionHandler(HttpMessageNotReadableException.class) public ...
Read more >HttpMessageNotReadableExcep...
BAD_REQUEST) public R handleError(HttpMessageNotReadableException e) { log.error("消息不能读取:{}", e. ... ControllerExceptionMapper.handle(...).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was hoping there was a more elegant way of hanlding exceptions instead of having to do below
If you throw an exception from a
ExceptionHandler
, will it be catched by anyControllerAdvice
again? I think I’ve seenJsonParseException
(not wrapped inside aHttpMessageNotReadableException
), which would be cool for this.