Description
When calling a remote service, it's important to know if an exception happened before sending the request or after receiving the response.
Unfortunately, not all exceptions are wrapped by WebClientResponseException
, WebClientException
or another subclass of WebClientException
when calling webClient.retrieve().bodyToFlux()
resp. webClient.retrieve().bodyToMono()
E.g.:
Before request:
java.net.ConnectException
io.netty.channel.ConnectTimeoutException
io.netty.handler.timeout.ReadTimeoutException
After response:
org.springframework.core.codec.DecodingException
org.springframework.core.codec.CodecException
could happen before request and after response, I guess. How can we detect this?
I also might have missed some exceptions.
Exception handling would be much easier if the following rule could be implemented:
if the exception happens after the response -> wrap the exception with a WebClientResponseException
, so we don't loose the http status code and the payload
else wrap the exception with a WebClientException
or another subclass.
I'm not sure if this a bug or an enhancement request.