From ebb92473d5c97bd9a0254f1428305e4c943d2b39 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Sat, 11 Feb 2023 16:59:40 -0800 Subject: [PATCH] handle errors from URL constructor --- extension/popup.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/extension/popup.js b/extension/popup.js index 35a032c..a3c60ec 100644 --- a/extension/popup.js +++ b/extension/popup.js @@ -44,18 +44,23 @@ document.getElementById('save-login').addEventListener('click', function () { if (!url.includes('://')) { url = 'http://' + url; } - let parsed = new URL(url); - let toStore = { - access: { - url: `${parsed.protocol}//${parsed.hostname}`, - port: parsed.port || (parsed.protocol === 'https:' ? '443' : '80'), - apiKey: document.getElementById('api-key').value, - }, - }; - browserType.storage.local.set(toStore, function () { - console.log('Stored connection details: ' + JSON.stringify(toStore)); - pingBackend(); - }); + try { + clearError(); + let parsed = new URL(url); + let toStore = { + access: { + url: `${parsed.protocol}//${parsed.hostname}`, + port: parsed.port || (parsed.protocol === 'https:' ? '443' : '80'), + apiKey: document.getElementById('api-key').value, + }, + }; + browserType.storage.local.set(toStore, function () { + console.log('Stored connection details: ' + JSON.stringify(toStore)); + pingBackend(); + }); + } catch (e) { + setError(e.message); + } }); // verify connection status