Merge pull request #701 from microwin7/support/5.5.x

[FEATURE]  Handle non 2XX codes in Downloader
This commit is contained in:
Gravit 2024-02-16 00:44:46 +07:00 committed by GitHub
commit 683be84cef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -183,7 +183,13 @@ public CompletableFuture<Void> downloadFiles(List<SizedFile> files, String baseU
} }
try { try {
DownloadTask task = sendAsync(file, baseUri, targetDir, callback); DownloadTask task = sendAsync(file, baseUri, targetDir, callback);
task.completableFuture.thenAccept(consumerObject.next).exceptionally(ec -> { task.completableFuture.thenCompose((res) -> {
if(res.statusCode() < 200 || res.statusCode() >= 300) {
return CompletableFuture.failedFuture(new IOException(String.format("Failed to download %s: code %d",
file.urlPath != null ? file.urlPath /* TODO: baseUri */ : file.filePath, res.statusCode())));
}
return CompletableFuture.completedFuture(res);
}).thenAccept(consumerObject.next).exceptionally(ec -> {
future.completeExceptionally(ec); future.completeExceptionally(ec);
return null; return null;
}); });