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

RestErrorHandler should not be limited to RestClientException #1002

Description

@tbruyelle

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 ?

Activity

  1. toshe commented on May 17, 2014

    @toshe
    Contributor

    +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.

  2. toshe commented on May 18, 2014

    @toshe
    Contributor

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

  3. added this to the 3.1 milestone on May 31, 2014
  4. WonderCsabo commented on Jun 1, 2014

    @WonderCsabo
    Member

    @DayS This can be closed now. :)

  5. tbruyelle commented on Jun 5, 2014

    @tbruyelle
    ContributorAuthor

    Thanks for the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions