diff --git a/src/background.js b/src/background.js index aacd7f7..fec21b4 100644 --- a/src/background.js +++ b/src/background.js @@ -392,7 +392,7 @@ async function getFullSettings() { }); var response = await hostAction(configureSettings, "configure"); if (response.status != "ok") { - throw new Error(JSON.stringify(response)); // TODO handle host error + settings.hostError = response; } settings.version = response.version; if (Object.keys(settings.stores).length > 0) { @@ -411,7 +411,7 @@ async function getFullSettings() { } } } - } else { + } else if (response.status == "ok") { // no user-configured stores, so use the default store settings.stores.default = { id: "default", @@ -593,7 +593,7 @@ async function handleMessage(settings, message, sendResponse) { } catch (e) { sendResponse({ status: "error", - message: "Unable to save settings" + e.toString() + message: e.message }); } break; @@ -863,9 +863,10 @@ async function saveSettings(settings) { // 'default' is our reserved name for the default store delete settingsToSave.stores.default; + // verify that the native host is happy with the provided settings var response = await hostAction(settingsToSave, "configure"); if (response.status != "ok") { - throw new Error(JSON.stringify(response)); // TODO handle host error + throw new Error(`${response.params.message}: ${response.params.error}`); } // before save, make sure to remove store settings that we receive from the host app diff --git a/src/options/interface.js b/src/options/interface.js index 9719bb3..e982875 100644 --- a/src/options/interface.js +++ b/src/options/interface.js @@ -76,6 +76,10 @@ function view(ctl, params) { if (typeof this.error !== "undefined") { nodes.push(m("div.error", this.error.message)); } + if (this.settings.hasOwnProperty("hostError")) { + let hostError = this.settings.hostError; + nodes.push(m("div.error", hostError.params.message)); + } nodes.push( m( @@ -84,7 +88,7 @@ function view(ctl, params) { disabled: !this.saveEnabled, onclick: async () => { try { - await this.saveSettings(this.settings); + this.settings = await this.saveSettings(this.settings); this.error = undefined; } catch (e) { this.error = e; diff --git a/src/options/options.js b/src/options/options.js index 6414482..a8fcb8d 100644 --- a/src/options/options.js +++ b/src/options/options.js @@ -33,6 +33,7 @@ function handleError(error, type = "error") { * @since 3.0.0 * * @param object settings Settings object + * @return object Settings object */ async function saveSettings(settings) { var response = await chrome.runtime.sendMessage({ @@ -42,6 +43,14 @@ async function saveSettings(settings) { if (response.status != "ok") { throw new Error(response.message); } + + // reload settings + var response = await chrome.runtime.sendMessage({ action: "getSettings" }); + if (response.status != "ok") { + throw new Error(response.message); + } + + return response.settings; } /** diff --git a/src/popup/popup.js b/src/popup/popup.js index 1947634..30cf842 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -67,6 +67,10 @@ async function run() { } var settings = response.settings; + if (settings.hasOwnProperty("hostError")) { + throw new Error(settings.hostError.params.message); + } + if (typeof settings.host === "undefined") { throw new Error("Unable to retrieve current tab information"); }