Skip to content

Commit 21c988b

Browse files
authored
check response code in docker compose downloader
check response code in docker compose downloader Closes #2066
2 parents 5fa3805 + d32ae64 commit 21c988b

File tree

1 file changed

+27
-14
lines changed
  • ide-common/src/main/kotlin/org/digma/intellij/plugin/docker

1 file changed

+27
-14
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/docker/Downloader.kt

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.digma.intellij.plugin.errorreporting.SEVERITY_PROP_NAME
88
import org.digma.intellij.plugin.log.Log
99
import java.io.File
1010
import java.io.FileOutputStream
11+
import java.net.HttpURLConnection
1112
import java.net.URL
1213
import java.nio.file.Files
1314
import java.nio.file.StandardCopyOption
@@ -96,22 +97,34 @@ class Downloader {
9697

9798
Log.log(logger::info, "downloading {}", url)
9899

99-
val connection = url.openConnection()
100-
connection.connectTimeout = 5000
100+
val connection: HttpURLConnection = url.openConnection() as HttpURLConnection
101+
connection.connectTimeout = 10000
101102
connection.readTimeout = 5000
102-
103-
connection.getInputStream().use {
104-
Files.copy(it, tempFile, StandardCopyOption.REPLACE_EXISTING)
105-
}
106-
107-
Log.log(logger::info, "copying downloaded file {} to {}", tempFile, toFile)
108-
try {
109-
Files.move(tempFile, toFile.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE)
110-
} catch (e: Exception) {
111-
//ATOMIC_MOVE is not always supported so try again on exception
112-
Files.move(tempFile, toFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
103+
connection.requestMethod = "GET"
104+
val responseCode: Int = connection.getResponseCode()
105+
106+
if (responseCode != HttpURLConnection.HTTP_OK) {
107+
ErrorReporter.getInstance().reportError(
108+
null, "Downloader.downloadAndCopyFile",
109+
"download from ${url.toString()}",
110+
mapOf(
111+
SEVERITY_PROP_NAME to SEVERITY_HIGH_TRY_FIX,
112+
"responseCode" to responseCode.toString()
113+
)
114+
)
115+
} else {
116+
connection.inputStream.use {
117+
Files.copy(it, tempFile, StandardCopyOption.REPLACE_EXISTING)
118+
}
119+
120+
Log.log(logger::info, "copying downloaded file {} to {}", tempFile, toFile)
121+
try {
122+
Files.move(tempFile, toFile.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE)
123+
} catch (e: Exception) {
124+
//ATOMIC_MOVE is not always supported so try again on exception
125+
Files.move(tempFile, toFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
126+
}
113127
}
114-
115128
}, Throwable::class.java, 5000, 3)
116129

117130
} catch (e: Exception) {

0 commit comments

Comments
 (0)