Affects: Spring Web 6.1.X
Given a simple method in FooInterface
such as
@GetExchange("/foo")
Mono<ResponseEntity<Foo>> getFoo();
with a 'standard' WebClient backing it.
The factory is also 'generic':
HttpServiceProxyFactory factory = HttpServiceProxyFactory
.builderFor(WebClientAdapter.create(webClient))
.build();
return factory.createClient(FooInterface.class);
When the client is used and a 40X or 50X response occurs, then the WebClient throws a WebClientResponseException
- which is unexpected - as I would think that having specified Mono<ResponseEntity<Foo>>
as the return type would have returned a ResponseEntity with status 40X or 50X (acknowledging the reactive component of this).
Looking at the factory code, it is aware of the return type, and therefore I would expect a response that is consistent with the declared return type - in other words, a Mono<ResponseEntity<Foo>>
.
I have not found a way to work around this - meaning obtaining a behavior consistent with the return type - in the same manner that exchange()
would work. This is another odd part of this, as exchange()
is deprecated and we now work with exchangeToMono()
- which is distinctly a client
feature that seems too low level to be a part of HTTP interface clients. So maybe - works as designed?
Instead, I've had to use the normal handling of errors to 'coerce' the behavior I want for a given method. With this, I can do what I want, but it seems this may be a bug - or something that can be clarified in the documentation.
Comment From: simonbasle
@amoffet the official way around this is to customize the underlying WebClient, as described in the HTTP interface client documentation's error handling section