@@ -8,6 +8,7 @@ import org.digma.intellij.plugin.errorreporting.SEVERITY_PROP_NAME
88import org.digma.intellij.plugin.log.Log
99import java.io.File
1010import java.io.FileOutputStream
11+ import java.net.HttpURLConnection
1112import java.net.URL
1213import java.nio.file.Files
1314import 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