diff options
author | 0neGal <mail@0negal.com> | 2022-08-09 08:44:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-09 08:44:30 +0200 |
commit | 5106d9ed409a3cc91a7755f961fab1bf91d8b7fb (patch) | |
tree | db6ac0c318b5a4c28d70be210ae29bf9730e11ac /src/extras/requests.js | |
parent | d124f8165f2fa690269c28770b35103eb2791a70 (diff) | |
parent | 7d84141d4cf91b02d5219a3e0f34b55e9d9f6247 (diff) | |
download | Viper-5106d9ed409a3cc91a7755f961fab1bf91d8b7fb.tar.gz Viper-5106d9ed409a3cc91a7755f961fab1bf91d8b7fb.zip |
Merge pull request #145 from Alystrasz/feat/no-internet-handling
feat: No internet handling
Diffstat (limited to 'src/extras/requests.js')
-rw-r--r-- | src/extras/requests.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/extras/requests.js b/src/extras/requests.js index 16b1330..7509e9e 100644 --- a/src/extras/requests.js +++ b/src/extras/requests.js @@ -2,6 +2,7 @@ const { app } = require("electron"); const path = require("path"); const fs = require("fs"); const { https } = require("follow-redirects"); +const lang = require("../lang"); // all requests results are stored in this file @@ -58,6 +59,11 @@ async function getLatestNsVersion() { _saveCache(cache); resolve( cache[NORTHSTAR_LATEST_RELEASE_KEY]["body"]["tag_name"] ); }); + }) + + .on('error', () => { + console.error('Failed to get latest Northstar version.'); + resolve( false ); }); } }); @@ -103,6 +109,20 @@ async function getNsReleaseNotes() { _saveCache(cache); resolve( cache[NORTHSTAR_RELEASE_NOTES_KEY]["body"] ); }); + }) + + // When GitHub cannot be reached (when user doesn't have Internet + // access for instance), we return latest cache content even if + // it's not up-to-date, or display an error message if cache + // is empty. + .on('error', () => { + if ( cache[NORTHSTAR_RELEASE_NOTES_KEY] ) { + console.warn("Couldn't fetch Northstar release notes, returning data from cache."); + resolve( cache[NORTHSTAR_RELEASE_NOTES_KEY]["body"] ); + } else { + console.error("Couldn't fetch Northstar release notes, cache is empty."); + resolve( [lang("request.northstar.noReleaseNotes")] ); + } }); } }); @@ -140,6 +160,20 @@ async function getVpReleaseNotes() { _saveCache(cache); resolve( cache[VIPER_RELEASE_NOTES_KEY]["body"] ); }); + }) + + // When GitHub cannot be reached (when user doesn't have Internet + // access for instance), we return latest cache content even if + // it's not up-to-date, or display an error message if cache + // is empty. + .on('error', () => { + if ( cache[VIPER_RELEASE_NOTES_KEY] ) { + console.warn("Couldn't fetch Viper release notes, returning data from cache."); + resolve( cache[VIPER_RELEASE_NOTES_KEY]["body"] ); + } else { + console.error("Couldn't fetch Viper release notes, cache is empty."); + resolve( [lang("request.viper.noReleaseNotes")] ); + } }); } }); |