From df1f1113208f16498d5f6a14092ebde550a08786 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Fri, 1 Jul 2022 12:06:41 -0400 Subject: [PATCH 1/2] Fix unhandled rejection for invalid response --- src/utils/dashboard.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/utils/dashboard.js b/src/utils/dashboard.js index 0052f4429e..c0edca8c68 100644 --- a/src/utils/dashboard.js +++ b/src/utils/dashboard.js @@ -50,30 +50,26 @@ export async function serverAddress() { console.debug('URL candidates:', urls); const promises = urls.map(url => { - return fetch(`${url}/System/Info/Public`).then(resp => { - return { - url: url, - response: resp - }; - }).catch(() => { - return Promise.resolve(); - }); + return fetch(`${url}/System/Info/Public`) + .then(async resp => { + if (!resp.ok) { + return; + } + + return { + url: url, + config: await resp.json() + }; + }).catch(() => { /* swallow errors */ }); }); return Promise.all(promises).then(responses => { - responses = responses.filter(obj => obj && obj.response.ok); - return Promise.all(responses.map(obj => { - return { - url: obj.url, - config: obj.response.json() - }; - })); + return responses.filter(obj => obj?.config); }).then(configs => { const selection = configs.find(obj => !obj.config.StartupWizardCompleted) || configs[0]; - return Promise.resolve(selection?.url); + return selection?.url; }).catch(error => { console.log(error); - return Promise.resolve(); }); } From 59c4f41ae93e622e4d6c59e394ce866b275e5691 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Mon, 11 Jul 2022 10:26:28 -0400 Subject: [PATCH 2/2] Update exception logging when connecting --- src/utils/dashboard.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/dashboard.js b/src/utils/dashboard.js index c0edca8c68..0101aa57d3 100644 --- a/src/utils/dashboard.js +++ b/src/utils/dashboard.js @@ -57,10 +57,12 @@ export async function serverAddress() { } return { - url: url, + url, config: await resp.json() }; - }).catch(() => { /* swallow errors */ }); + }).catch(error => { + console.error(error); + }); }); return Promise.all(promises).then(responses => { @@ -69,7 +71,7 @@ export async function serverAddress() { const selection = configs.find(obj => !obj.config.StartupWizardCompleted) || configs[0]; return selection?.url; }).catch(error => { - console.log(error); + console.error(error); }); }