fix: FileDownloadTask does not fail if 404.

This commit is contained in:
huanghongxun
2021-09-18 23:26:37 +08:00
parent 28cc7c0700
commit ea9f547ada
2 changed files with 11 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.i18n.I18n; import org.jackhuang.hmcl.util.i18n.I18n;
import org.jackhuang.hmcl.util.io.ResponseCodeException; import org.jackhuang.hmcl.util.io.ResponseCodeException;
import java.io.FileNotFoundException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
@@ -147,6 +148,8 @@ public final class DownloadProviders {
} else { } else {
return i18n("install.failed.downloading.detail", url) + "\n" + StringUtils.getStackTrace(exception.getCause()); return i18n("install.failed.downloading.detail", url) + "\n" + StringUtils.getStackTrace(exception.getCause());
} }
} else if (exception.getCause() instanceof FileNotFoundException) {
return i18n("download.code.404", url);
} else { } else {
return i18n("install.failed.downloading.detail", url) + "\n" + StringUtils.getStackTrace(exception.getCause()); return i18n("install.failed.downloading.detail", url) + "\n" + StringUtils.getStackTrace(exception.getCause());
} }

View File

@@ -27,6 +27,7 @@ import org.jackhuang.hmcl.util.io.NetworkUtils;
import org.jackhuang.hmcl.util.io.ResponseCodeException; import org.jackhuang.hmcl.util.io.ResponseCodeException;
import java.io.Closeable; import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@@ -117,7 +118,7 @@ public abstract class FetchTask<T> extends Task<T> {
continue; continue;
} }
} else if (responseCode / 100 == 4) { } else if (responseCode / 100 == 4) {
break; // we will not try this URL again throw new FileNotFoundException();
} else if (responseCode / 100 != 2) { } else if (responseCode / 100 != 2) {
throw new ResponseCodeException(url, responseCode); throw new ResponseCodeException(url, responseCode);
} }
@@ -157,6 +158,12 @@ public abstract class FetchTask<T> extends Task<T> {
} }
return; return;
} catch (FileNotFoundException ex) {
failedURL = url;
exception = ex;
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", not found", ex);
break; // we will not try this URL again
} catch (IOException ex) { } catch (IOException ex) {
failedURL = url; failedURL = url;
exception = ex; exception = ex;