aboutsummaryrefslogtreecommitdiff
path: root/src/extras/requests.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-10-23 03:26:54 +0200
committer0neGal <mail@0negal.com>2022-10-23 03:29:23 +0200
commit0862c82996f11822fa851eeebc247d12f88dcd7d (patch)
tree2084b900a35eeccce2d0a027df3b49dc8d1e29d1 /src/extras/requests.js
parentefb5761268d1ced56cc633347a5143343aa957c6 (diff)
parent096c54e746def93eb6ee1b2a8d91e1e62555d610 (diff)
downloadViper-0862c82996f11822fa851eeebc247d12f88dcd7d.tar.gz
Viper-0862c82996f11822fa851eeebc247d12f88dcd7d.zip
Merge branch 'main' into linux-launch
Diffstat (limited to 'src/extras/requests.js')
-rw-r--r--src/extras/requests.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/extras/requests.js b/src/extras/requests.js
index 16b1330..a5f3121 100644
--- a/src/extras/requests.js
+++ b/src/extras/requests.js
@@ -2,10 +2,11 @@ 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
-const cachePath = path.join(app.getPath("cache"), "requests.json");
+const cachePath = path.join(app.getPath("cache"), "viper-requests.json");
const NORTHSTAR_LATEST_RELEASE_KEY = "nsLatestRelease";
const NORTHSTAR_RELEASE_NOTES_KEY = "nsReleaseNotes";
const VIPER_RELEASE_NOTES_KEY = "vpReleaseNotes";
@@ -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")] );
+ }
});
}
});