Skip to content

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

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

Closed
spring-projects-issues opened this issue Oct 26, 2018 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

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

Backported to: 5.0.11, 4.3.21

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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-projects-issues
Copy link
Collaborator Author

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
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

2 participants