mirror of
https://github.com/cryptoadvance/specter-desktop.git
synced 2026-08-13 12:33:29 +02:00
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:
parent
041df50d0d
commit
69dae28c63
1 changed files with 18 additions and 2 deletions
|
|
@ -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']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue