Closed ZIRAKrezovic closed 1 month ago
A filter provides full control, including handling of early exception like WebClientRequestException
. However, ExchangeFilterFunction#ofResponseProcessor
isn't the right hook. The flatMap here is called if the exchange produces a response. What you need instead is to handle an error signal.
For example:
ResponseEntity<String> entity = WebClient.builder()
.filter((request, next) ->
next.exchange(request)
.onErrorResume(WebClientRequestException.class, ex -> {
System.out.println("Got: " + ex.getMessage());
return Mono.error(ex);
}))
.build()
.get().uri("http://invalid/path")
.retrieve()
.toEntity(String.class)
.block();
Results in:
19:45:54.246 [Test worker] DEBUG o.s.w.r.f.c.ExchangeFunctions - [350ec690] HTTP GET http://invalid/path
Got: Failed to resolve 'invalid' [A(1)]
The above just intercepts, prints, and propagates the same exception, but you can handle it in any way you want, or user another error operator as needed.
Affects: 6.1.11
I am following https://docs.spring.io/spring-framework/reference/integration/rest-clients.html#rest-http-interface-exceptions and I'm trying to map exceptions from all 3 supported adapter clients to ones that do not have a dependency on concrete web stack dependency.
For handling response from WebFlux WebClient, the following is recommended in the linked guide
However, this does not cover the low level exception ,
org.springframework.web.reactive.function.client.WebClientRequestException
. Simplest way to trigger it is to give non-existing hostname as a URL.Is there a possibility to somehow plug in into the exchange function and re-map the
org.springframework.web.reactive.function.client.WebClientRequestException
to something else? I am not able to find a way with Spring Framework 6.1.11If I understand correctly, this is the equivalent of
ResourceAccessException
usually thrown in non-reactive RestClient(RestTemplate).I have tried
Where
SpringWebCompatibleStatusHandler
is as followsNone of the functions is called before or after I get
WebClientRequestException