Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

RestErrorHandler should not be limited to RestClientException #1002

Closed
tbruyelle opened this issue May 14, 2014 · 4 comments
Closed

RestErrorHandler should not be limited to RestClientException #1002

tbruyelle opened this issue May 14, 2014 · 4 comments
Milestone

Comments

@tbruyelle
Copy link
Contributor

The RestTemplate doesn't throw only RestClientExceptions. In my case, when the mobile connection is lost, I can get a HttpMessageNotReadableException :

org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: recvfrom failed: ETIMEDOUT (Connection timed
                            out); nested exception is java.net.SocketException: recvfrom failed: ETIMEDOUT (Connection timed out)
                        E   at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal(MappingJacksonHttpMessageConverter.java:1
                           25)
                        E   at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:147)
                        E   at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:76)
                        E   at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:655)
                        E   at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:641)
                        E   at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
                        E   at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:447)
                        E   at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:422)

The exception is not catched and so my app crashes miserably.
Maybe AA should allow RestErrorHandler to catch all kinds of RuntimeExceptions ?

@toshe
Copy link
Contributor

toshe commented May 17, 2014

+1, this should definitely be the case, HttpMessageConversionException is thrown when there's a SocketException or org.apache.http.conn.HttpHostConnectException!
RestErrorHandler and Spring's ResponseErrorHandler are only used once there is a valid connection so that the response can be identified; if something else happens (WiFi disconnect, server not reachable due to timeout) then you have to manually catch IOExceptions, which is definitely not a best practice solution.

@toshe
Copy link
Contributor

toshe commented May 18, 2014

I have created a merge request #1006 to address this issue.

@DayS DayS added this to the 3.1 milestone May 31, 2014
@WonderCsabo
Copy link
Member

@DayS This can be closed now. :)

@DayS DayS closed this as completed Jun 1, 2014
@tbruyelle
Copy link
Contributor Author

Thanks for the PR

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants