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

spring-projects-issues opened this issue Jul 5, 2017 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues 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.


                .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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants