英文:
How to get original error message from guava retryer?
问题
我在一段代码周围使用了Guava的重试机制:
Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
.retryIfExceptionOfType(Exception.class)
.withStopStrategy(5)
.withWaitStrategy(exponential wait (10, 30, seconds)
.build();
try {
return retryer.call(myMethod);
} catch (ExecutionException | RetryException e) {
throw new MyErrorWrapper(e.getMessage(), e);
}
然而,我在主应用程序中只收到一个错误消息,内容为"在经过X次尝试后,重试操作未能成功完成"。我理解这是因为Guava的重试机制一旦达到5次尝试限制,就会抛出RetryException,但是否有办法将导致此错误的原始错误消息传播回我的主应用程序?
英文:
I have a Guava retryer around some code:
Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
.retryIfExceptionOfType(Exception.class)
.withStopStrategy(5)
.withWaitStrategy(exponential wait (10, 30, seconds)
.build();
try {
return retryer.call(myMethod);
} catch (ExecutionException | RetryException e) {
throw new MyErrorWrapper(e.getMessage(), e);
}
However, the only error message I get propgated to my main application is Retrying failed to complete successfully after X attempts. I understand this is because the guave retryer is throwing a RetryException once it hits the limit of 5 but is there any way to get th eoriginal error message that caused this back up to my main app?
专注分享java语言的经验与见解,让所有开发者获益!
评论