From 5b742bc1a1905ab4275086e0bdb6c391448aa19c Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Sat, 29 May 2021 17:38:24 +0100 Subject: [PATCH] Fix hidden error if request was never even started If a HTTP request failed to even connect, then the logic determining whether to retry a partial download would inadvertently throw an error before it could re-throw the causing error, which resulted in a confusing error dialog. --- .../com/skcraft/launcher/install/HttpDownloader.java | 2 +- .../main/java/com/skcraft/launcher/util/HttpRequest.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/install/HttpDownloader.java b/launcher/src/main/java/com/skcraft/launcher/install/HttpDownloader.java index 6c5aeea..ccc3f47 100644 --- a/launcher/src/main/java/com/skcraft/launcher/install/HttpDownloader.java +++ b/launcher/src/main/java/com/skcraft/launcher/install/HttpDownloader.java @@ -269,7 +269,7 @@ public class HttpDownloader implements Downloader { // We only want to try to resume a partial download if the request succeeded before // throwing an exception halfway through. If it didn't succeed, just throw the error. - if (tries >= tryCount || !request.isSuccessCode()) { + if (tries >= tryCount || !request.isConnected() || !request.isSuccessCode()) { throw e; } diff --git a/launcher/src/main/java/com/skcraft/launcher/util/HttpRequest.java b/launcher/src/main/java/com/skcraft/launcher/util/HttpRequest.java index 3f05cd3..6bf1457 100644 --- a/launcher/src/main/java/com/skcraft/launcher/util/HttpRequest.java +++ b/launcher/src/main/java/com/skcraft/launcher/util/HttpRequest.java @@ -265,6 +265,15 @@ public class HttpRequest implements Closeable, ProgressObservable { return inputStream; } + /** + * Check if a connection was ever made + * + * @return True if a connection is available, false otherwise + */ + public boolean isConnected() { + return conn != null; + } + /** * Buffer the returned response. *