达到最大重试次数时如何引发异常。
就我而言,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()
答案 0 :(得分:1)
当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);