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

RestTemplate does not throw exception for custom error codes [SPR-17439] #21971

Closed
spring-issuemaster opened this issue Oct 26, 2018 · 2 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Oct 26, 2018

shollander opened SPR-17439 and commented

Normally, RestTemplate is expected to throw an exception if the server returns an HTTP error code. However, is the server returns a custom error code (4xx or 5xx), no exception is thrown and the call returns normally.


Affects: 4.3.20, 5.0.10

Issue Links:

  • #20529 RestTemplate doesn't consistently tolerate unknown HTTP status codes
  • #20656 DefaultResponseErrorHandler.hasError doesn't tolerate unknown status codes
  • #20918 RestTemplate.ResponseEntityResponseExtractor doesn't tolerate unknown status codes
  • #21145 DefaultResponseErrorHandler wastes the body of a response with an unknown status
  • #21993 DefaultResponseErrorHandler does not handle status values outside of HttpStatus enum

Referenced from: commits 97ac1c2, 4a51acb, 1c1b942, 738097d

Backported to: 5.0.11, 4.3.21

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 29, 2018

Rossen Stoyanchev commented

Juergen Hoeller I can see that #20529 brought some changes to DefaultResponseErrorHandler to improve support for custom response codes. Now getHttpStatusCode(ClientHttpResponse) is deprecated in favor of handleError(ClientHttpResponse, HttpStatus) but hasError only detects errors for values in the HttpStatus enum range. So I don't see how handleError would ever be called for a custom 4xx or 5xx code, whereas previously that would have caused an UnknownHttpStatusCodeException.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 23, 2018

Juergen Hoeller commented

Resolved on master through a raw status code check for client/server errors in case of an unresolvable HttpStatus enum. To be backported to 5.0.x and 4.3.x later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.