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

Revisit handling of 4xx and 5xx status codes in WebClient [SPR-15486] #20046

Closed
spring-projects-issues opened this issue Apr 26, 2017 · 3 comments
Closed
Assignees
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Apr 26, 2017

Arjen Poutsma opened SPR-15486 and commented

Currently, we throw a WebClientException for 4xx and 5xx status codes in ClientResponse.bodyToMono(Class) and ClientResponse.bodyToFlux(Class) (but not ClientResponse.body(BodyExtractor). The underlying thought here was that the response format of a 4xx or 5xx error typically does not take the same form as a "regular" 2xx response. Now that we have the ResponseSpec in WebClient, let's revisit this handling of 4xx and 5xx status codes on the client side.

I think the rule to throwing an exception should be simple: if there is no way for the user to get the response status code, then a WebClientException should be returned. If there is a way to get to the status code, then we should not return an exception.

In our current WebClient, this rule would bring the following changes:

  1. WebClient.ResponseSpec.bodyToMono and bodyToFlux should return WebClientException when the response status code is 4xx or 5xx.
  2. WebClient.ResponseSpec.bodyToEntity and bodyToEntityList should not return an exception in these cases, because you can get access to the status code through ResponseEntity.getStatusCode().
  3. ClientResponse.bodyToMono and bodyToFlux should not return an exception, as the ClientResponse exposes the response status code through statusCode().

All other WebClient/ClientResponse methods should keep their current behaviour.


Issue Links:

  • #20295 ResponseSpec#toEntity(...) fails when response status code is 5xx
  • #19860 Simplify access to request/response object in WebClient

Referenced from: commits 4a8c99c, 0e7d6fc

1 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 26, 2017

Logan Mauzaize commented

Can you add renaming of bodyToEntityXxx as discuss in ##19860 ?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 26, 2017

Arjen Poutsma commented

Right, I will also rename bodyToEntity to toEntity and bodyToEntityList to toEntityList as part of this change.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 26, 2017

Arjen Poutsma commented

Fixed in 0e7d6fc and 4a8c99c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants