I have the following error handling in RestTemplate
:
try {
restTemplate.postForObject(..);
} catch (ResourceAccessException e) {
throw new CustomException("host is down");
}
Question: how can I achieve the same with spring WebClient
?
try {
webClient.post()...block();
} catch (Exception e) {
//cannot check due to package private access
//if (e instanceof Exceptions.ReactiveException)
if (e.getCause() instanceof java.net.ConnectException) {
throw new CustomException("host is down");
}
}
Problem: I cannot directly catch ConnectionException
because it is wrapped inside the ReactiveException
. Could I do better than applying multiple instanceof
checks for any real underlying exceptions?