如何从Guava Retryer获取原始错误消息?

huangapple 未分类评论42阅读模式
英文:

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&lt;Boolean&gt; retryer = RetryerBuilder.&lt;Boolean&gt;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?

huangapple
  • 本文由 发表于 2020年4月10日 01:47:49
  • 转载请务必保留本文链接:https://java.coder-hub.com/61127136.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定