Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultResponseErrorHandler wastes the body of a response with an unknown status [SPR-16604] #21145

Closed
spring-projects-issues opened this issue Mar 16, 2018 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 16, 2018

Milos Cubrilo opened SPR-16604 and commented

RestTemplate.handleResponse calls ResponseErrorHandler.hasError(response) to check if it should delegate error handling to ResponseErrorHandler instance.

In case of an unknown status code, DefaultResponseErrorHandler.hasError swallows the exception thrown by DefaultResponseErrorHandler.getHttpStatusCode(response) and returns false.

This causes RestTemplate code to proceed with standard response handling, but without possibility to read message body, which has already been consumed during UnknownHttpStatusCodeException creation in DefaultResponseErrorHandler.getHttpStatusCode(response) call.


Affects: 4.3.14

Issue Links:

Referenced from: pull request #1742, and commits 3b3f27d, d95bbb6

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Indeed, for hasError purposes, we should locally resolve the status code and catch the IllegalArgumentException instead. I'll revise this for 4.3.15.

Note that this has been resolved for 5.0 already where HTTP status code resolution has been streamlined in several places.

@spring-projects-issues
Copy link
Collaborator Author

Denys Ivano commented

I also faced difficulties with unknown status codes. We have some logic based on catching and processing RestClientResponseException, especially it's subclass - UnknownHttpStatusCodeException. But in 4.3.12 new approach was introduced, so we can't even get response data w/o providing custom ResponseErrorHandler. Maybe it would be better to make hasError() method work the same way as it works in Spring Framework 5. I've submitted pull request which is able to resolve this issue. I hope this will help.
#1742

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Resolved through direct enum value comparisons in hasError (without an intermediate exception and therefore as analogous as possible to the 5.0 code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants