From 6f167c101b1181be14cc8ecb199a5791ba48c46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Tue, 14 Jan 2025 16:28:22 +0100 Subject: [PATCH] #916: download status code error handling (#917) --- CHANGELOG.adoc | 1 + .../main/java/com/devonfw/tools/ide/io/FileAccessImpl.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1b8260226..40941d153 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE Release with new features and bugfixes: +* https://github.com/devonfw/IDEasy/issues/916[#916]: download is missing status code error handling * https://github.com/devonfw/IDEasy/issues/757[#757]: Support to allow settings in code repository * https://github.com/devonfw/IDEasy/issues/826[#826]: Fix git settings check when settings folder is empty * https://github.com/devonfw/IDEasy/issues/894[#894]: Fix ide.bat printing for initialization and error output diff --git a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java index 2100ad327..30a16b46f 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java @@ -98,8 +98,11 @@ public void download(String url, Path target) { HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).GET().build(); HttpClient client = createHttpClient(url); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofInputStream()); - if (response.statusCode() == 200) { + int statusCode = response.statusCode(); + if (statusCode == 200) { downloadFileWithProgressBar(url, target, response); + } else { + throw new IllegalStateException("Download failed with status code " + statusCode); } } else if (url.startsWith("ftp") || url.startsWith("sftp")) { throw new IllegalArgumentException("Unsupported download URL: " + url);