我有以下错误处理RestTemplate
:
try {
restTemplate.postForObject(..);
} catch (ResourceAccessException e) {
throw new CustomException("host is down");
}
问题:我怎样才能用 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");
}
}
问题:我无法直接捕获ConnectionException
,因为它被包裹在ReactiveException
. 我能比instanceof
对任何真正的潜在异常应用多次检查做得更好吗?