【发布时间】:2019-12-18 21:29:44
【问题描述】:
我在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 检查任何真正的潜在异常做得更好吗?
【问题讨论】:
标签: java spring spring-webflux spring-webclient