diff options
author | Alystrasz <contact@remyraes.com> | 2022-08-05 01:12:59 +0200 |
---|---|---|
committer | Alystrasz <contact@remyraes.com> | 2022-08-05 01:12:59 +0200 |
commit | 944363c06995196f68a57997973b11eac93d7d59 (patch) | |
tree | 8ba0592730b1f1ecc3f262fed19380ea19da416e /src/extras | |
parent | bea0f483d7bbfbd0d8311ff69c1f04d4798a4bbb (diff) | |
download | Viper-944363c06995196f68a57997973b11eac93d7d59.tar.gz Viper-944363c06995196f68a57997973b11eac93d7d59.zip |
feat: handle release notes fetching with no internet
When release notes (either Northstar or Viper) fetching fails,
if cache contains data, we display it even if it's outdated; if
cache is empty, we display an error message in place of release
notes.
Diffstat (limited to 'src/extras')
-rw-r--r-- | src/extras/requests.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/extras/requests.js b/src/extras/requests.js index 16b1330..c609da3 100644 --- a/src/extras/requests.js +++ b/src/extras/requests.js @@ -103,6 +103,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( ["Couldn't fetch Northstar release notes.\nTry again later!"] ); + } }); } }); @@ -140,6 +154,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( ["Couldn't fetch Viper release notes.\nTry again later!"] ); + } }); } }); |