Description
Kristoffer Peterhänsel opened SPR-13592 and commented
When using a RestTemplate
instance within a Spring MVC application, client exceptions may propagate in the MVC stack and can be wrongly mapped by server ExceptionHandlers
, leading to a wrong HTTP response sent to the browser sending a request to the MVC application.
The RestTemplate
instance uses HttpMessageConverter
to decode the remote service responses; and when those fail decoding an HTTP response, they can throw an HttpMessageNotReadableException
. That exception then bubbles up through the HttpMessageConverterExtractor
, RestTemplate
and the whole MVC stack, later mapped to HTTP 400 responses, since those exceptions can also be throws by the server stack when the incoming requests can't be deserialized.
Such exceptions should be nested under a RestClientException
to avoid erroneous server responses and confusing situations for developers.
Affects: 4.1.5
Issue Links:
- Revisit CodecException vs ResponseStatusException in DecoderHttpMessageReader [SPR-15516] #20075 Revisit CodecException vs ResponseStatusException in DecoderHttpMessageReader
- Consistent throwing of HttpMessageNotReadableException in HttpMessageConverter implementations [SPR-16995] #21533 Consistent throwing of HttpMessageNotReadableException in HttpMessageConverter implementations