如何在达到最大重试次数时抛出异常。在我的例子中,当Response有200以外的代码时,我想抛出异常。
Retry retry = RetryRegistry.of(
RetryConfig.<Response> custom()
.retryOnResult({ it.statusCode() != 200 })
.build())
.retry("my-retry")
Response response = Retry.decorateSupplier(retry, { foo.bar() }).get()发布于 2019-07-31 14:07:46
当HTTP代码不是200时,您可以包装代码并抛出异常。
例如,在Java代码中:
Supplier<Response> supplier= () -> foo.bar();
Supplier<String> supplierWithResultHandling = SupplierUtils.andThen(supplier, result -> {
if (result.statusCode().is4xxClientError()) {
throw new HttpClientErrorException(result.statusCode());
} else if (result.statusCode().is5xxServerError()) {
throw new HttpServerErrorException(result.statusCode());
}
return result;
});
Response response = retry.executeSupplier(supplierWithResultHandling);https://stackoverflow.com/questions/57243021
复制相似问题