From 944363c06995196f68a57997973b11eac93d7d59 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Fri, 5 Aug 2022 01:12:59 +0200 Subject: 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. --- src/app/launcher.js | 14 +++++++++----- src/extras/requests.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/app/launcher.js b/src/app/launcher.js index fbeb703..e1dbbe0 100644 --- a/src/app/launcher.js +++ b/src/app/launcher.js @@ -26,13 +26,17 @@ function page(page) { function formatRelease(notes) { let content = ""; - for (let release of notes) { - if (release.prerelease) {continue} - content += "# " + release.name + "\n\n" + release.body + "\n\n\n"; + if (notes.length === 1) { + content = notes[0]; + } else { + for (let release of notes) { + if (release.prerelease) {continue} + content += "# " + release.name + "\n\n" + release.body + "\n\n\n"; + } + + content = content.replaceAll(/\@(\S+)/g, `@$1`); } - content = content.replaceAll(/\@(\S+)/g, `@$1`); - return markdown(content, { breaks: true }); 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!"] ); + } }); } }); -- cgit v1.2.3