{"record":{"id":"79f37ce6451e0dbf","repo":"microg/GmsCore","slug":"failed-to-download-file-http-response-code-conn","errorCode":null,"errorMessage":"Failed to download file: HTTP response code ${connection.responseCode}","messagePattern":"Failed to download file: HTTP response code (.+?)","errorType":"http","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"vending-app/src/main/kotlin/com/google/android/finsky/DownloadManager.kt","lineNumber":184,"sourceCode":"        Log.d(TAG, \"Download for module $moduleName has been canceled.\")\n        downloadingRecord[moduleName]?.cancel(true)\n        shouldStops = true\n        notifyBuilderMap[moduleName]?.setOngoing(false)\n        NotificationManagerCompat.from(context).cancel(NOTIFICATION_ID)\n    }\n\n    private fun startDownload(moduleName: String, downloadLink: String, destinationFile: File, downloadData: DownloadData) {\n        val packData = downloadData.getModuleData(moduleName)\n        val uri = Uri.parse(downloadLink).toString()\n        val connection = URL(uri).openConnection() as HttpURLConnection\n        var bytes: Long = 0\n        try {\n            connection.requestMethod = \"GET\"\n            connection.connectTimeout = 20000\n            connection.readTimeout = 20000\n            connection.connect()\n            if (connection.responseCode != HttpURLConnection.HTTP_OK) {\n                throw IOException(\"Failed to download file: HTTP response code ${connection.responseCode}\")\n            }\n            if (destinationFile.exists()) {\n                destinationFile.delete()\n            } else destinationFile.parentFile?.mkdirs()\n\n            connection.inputStream.use { input ->\n                FileOutputStream(destinationFile).use { output ->\n                    val buffer = ByteArray(4096)\n                    var bytesRead: Int\n                    while (input.read(buffer).also { bytesRead = it } != -1) {\n                        if (shouldStops) {\n                            Log.d(TAG, \"Download interrupted for module: $moduleName\")\n                            downloadData.updateDownloadStatus(moduleName, AssetPackStatus.CANCELED)\n                            return\n                        }\n                        output.write(buffer, 0, bytesRead)\n                        bytes += bytesRead.toLong()\n                        downloadData.incrementModuleBytesDownloaded(moduleName, bytesRead.toLong())","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/vending-app/src/main/kotlin/com/google/android/finsky/DownloadManager.kt#L166-L202","documentation":"Download failure in DownloadManager.startDownload: the HTTP response code for the module file was not a success code (connection.responseCode embedded in the message), so the module download for the given destination file failed.","triggerScenarios":"Thrown at vending-app/src/main/kotlin/com/google/android/finsky/DownloadManager.kt:184 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the download — server errors are often transient","Verify the download link is valid and not expired","Check connectivity and notify the user, cancelling the progress notification on permanent failure"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}