Fix offline crash in Electron app: guard undefined response in download HEAD request and show user-facing error (#2595)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: k9ert <117085+k9ert@users.noreply.github.com>
This commit is contained in:
Copilot 2026-04-09 16:05:52 +02:00 committed by GitHub
parent 041df50d0d
commit 69dae28c63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,10 +36,11 @@ function downloadSpecterd(specterdPath) {
logger.info('Using platformName ' + platformName)
download_location = getDownloadLocation(appSettings.specterdVersion, platformName)
logger.info('Downloading from ' + download_location)
download(download_location, specterdPath + '.zip', function (errored) {
download(download_location, specterdPath + '.zip', function (errored, errorMsg) {
if (errored == true) {
updatingLoaderMsg(
`Downloading the ${appNameLower} binary from GitHub failed, could not reach the server or the file wasn't found.`
errorMsg ||
`Downloading the ${appNameLower} binary from GitHub failed, could not reach the server or the file wasn't found.`
)
updateSpecterdStatus(`Downloading ${appNameLower}d failed...`)
return
@ -83,6 +84,21 @@ function downloadSpecterd(specterdPath) {
const download = (uri, filename, callback) => {
// HEAD request first
request.head(uri, (err, res, body) => {
if (err || !res) {
logger.error(
`Network error while trying to download specterd: ${err ? err.message : 'No response received (offline?)'}`
)
try {
callback(
true,
`Downloading the ${appNameLower} binary from GitHub failed: no internet connection. Please check your network and try again.`
)
} catch (error) {
logger.error(error)
throw error
}
return
}
if (res.statusCode != 404) {
let receivedBytes = 0
const totalBytes = res.headers['content-length']