From d40dc09acaa30a321221199c049b18491f3ca4e4 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 15 Feb 2024 01:31:27 +0700 Subject: [PATCH] [FEATURE] Handle non 2XX codes in Downloader --- .../main/java/pro/gravit/launcher/base/Downloader.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java index 94782b7a..4517bdc2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java @@ -190,7 +190,13 @@ public CompletableFuture downloadFiles(List files, String baseU } try { 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); return null; });