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

ResponseSpec#toEntity(...) fails when response status code is 5xx [SPR-15739] #20295

Closed
spring-issuemaster opened this issue Jul 5, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jul 5, 2017

Doron Gold opened SPR-15739 and commented

The documentation of WebClient.ResponseSpec#toEntity() states the following:

this method does not check for a 4xx or 5xx status code before extracting the body

However, when a WebClient receives a 5xx response, it fails in the underlying Netty HTTP client layer. An error Mono is emitted before toEntity(...) finishes.
So there is no way to inspect the returned ResponseEntity in case we are interested in the body, headers or any other details of the response.

Example:

WebClient.create()
                .get()
                .uri("http://localhost:8080/error")
                .retrieve()
                .toEntity(String.class)
                .map(responseEntity -> {
                    //never reaches here because the underlying reactor.ipc.netty.http.client.HttpClient
                    // emits an error Mono from reactor.ipc.netty.http.client.HttpClientOperations#checkResponseCode()
                    if (responseEntity.getStatusCode()
                            .is5xxServerError()) {
                        throw new RuntimeException("Custom Server Error Exception");
                    }
                    return responseEntity.getBody();
                })

A relevant question on StackOverflow: https://stackoverflow.com/questions/44593066/spring-webflux-webclient-get-body-on-error


Affects: 5.0 RC2

Reference URL: spring-projects/spring-framework-issues#162

Issue Links:

  • #20046 Revisit handling of 4xx and 5xx status codes in WebClient

Referenced from: commits b0ab846

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 6, 2017

Arjen Poutsma commented

Fixed in b0ab846

Thanks for reporting this issue!

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