diff options
author | 0neGal <mail@0negal.com> | 2022-08-17 18:25:52 +0200 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-08-17 18:25:52 +0200 |
commit | 1da94c96948511b3b69f82b502265735c0c005e4 (patch) | |
tree | c4dd8d040a5e86cc18fbee4cc31c513f5f8666ac /src/extras/requests.js | |
parent | 19e3f0d2d44087036712dccf1b2b0b81b9df759a (diff) | |
parent | 5106d9ed409a3cc91a7755f961fab1bf91d8b7fb (diff) | |
download | Viper-1da94c96948511b3b69f82b502265735c0c005e4.tar.gz Viper-1da94c96948511b3b69f82b502265735c0c005e4.zip |
Merge branch 'main' of https://github.com/0neGal/viper
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")] ); + } }); } }); |