-
Hi, I'm using Unirest Here's the simplified code: public void downloadLargeJson(Params params, File targetFile) {
Unirest.post(URL)
.body(new Gson().toJson(params))
.thenConsume(response -> {
if (response.getStatus() != 200) {
log.error("http code: {}, response: {}", response.getStatus(), response.getContentAsString());
throw new RuntimeException("request fail");
}
try (InputStream responseStream = response.getContent()) {
writeInputStreamToFile(responseStream, targetFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} And here's how I've set up the retry logic: public void downloadLargeJsonWithRetry(Params params, File targetFile) {
RetryPolicy<Object> retryPolicy = RetryPolicy.builder()
.handle(RuntimeException.class)
.withDelay(Duration.ofSeconds(10))
.withMaxRetries(5)
.build();
Failsafe.with(retryPolicy).run(() -> downloadLargeJson(params, targetFile));
} The retry logic is intended to handle failed requests, but it doesn't seem to activate upon exceptions thrown within .thenConsume. Could you provide guidance on ensuring that the retry logic works as intended for both HTTP errors and file writing issues? Thanks in advance for your assistance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
What version are you on? |
Beta Was this translation helpful? Give feedback.
This was "fixed" in the 4.x line. see #506
There are no plans to backport this into the 3.x line which is only being maintained for security issues at this point