-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Document that NoOpResponseErrorHandler is to be used with the RestTemplate #33276
Comments
Expectation is actually incorrect, because However, the bottom line is the same: I see no proper method to remove default handling of 4xx/5xx statuses. |
Thanks for the report. I agree that it's a little odd that the only way to disable the behavior is to implement an error handler that claims there is an error for every request. Looking at Lines 549 to 550 in fc28926
I think the difference here is that the status handler uses a predicate based on the status code and you can indeed disable everything by using a predicate that always match. Perhaps Wondering what the rest of the team thinks. |
That means a |
Sounds good. Probably the linked reference page could have an explicit example that in order to disable status handling one needs configuration like this (I have not checked) RestClient restClient = RestClient.builder()
.defaultStatusHandler((statusCode) -> true, (request, response) -> {})
.build(); |
Thanks for the suggestion. I think the main goal here is to clarify that |
Affects: spring-web-6.1.11
Code
Let's pretend I don't want to handle status codes in the status handlers.
Expected
Default status handler is overridden, there should be no status code handling, no exception thrown.
Actual
Reason: while the built
RestClient
contains only a singleNoOpResponseErrorHandler
, aretrieve()
call creates anorg.springframework.web.client.DefaultRestClient.DefaultResponseSpec
which puts an additional defaultStatusHandler
at the end of the handlers list.spring-framework/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java
Lines 651 to 652 in fc28926
and the handlers are tried sequentially
spring-framework/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java
Lines 747 to 752 in fc28926
So, it's only possible to override the default error handler but not possible to replace it.
Workaround
Implement a handler so it returns true from
hasError
but does nothing in the handler. This looks more like abuse than following a contract.The text was updated successfully, but these errors were encountered: