diff options
Diffstat (limited to 'ext/fg')
-rw-r--r-- | ext/fg/js/frontend-api-receiver.js | 5 | ||||
-rw-r--r-- | ext/fg/js/frontend-api-sender.js | 8 | ||||
-rw-r--r-- | ext/fg/js/popup-proxy.js | 2 | ||||
-rw-r--r-- | ext/fg/js/util.js | 8 |
4 files changed, 11 insertions, 12 deletions
diff --git a/ext/fg/js/frontend-api-receiver.js b/ext/fg/js/frontend-api-receiver.js index 687e5c3c..fbfb3ab0 100644 --- a/ext/fg/js/frontend-api-receiver.js +++ b/ext/fg/js/frontend-api-receiver.js @@ -46,9 +46,8 @@ class FrontendApiReceiver { result => { this.sendResult(port, id, senderId, {result}); }, - e => { - const error = typeof e.toString === 'function' ? e.toString() : e; - this.sendResult(port, id, senderId, {error}); + error => { + this.sendResult(port, id, senderId, {error: errorToJson(error)}); }); } diff --git a/ext/fg/js/frontend-api-sender.js b/ext/fg/js/frontend-api-sender.js index 2e037e62..c6eeaeb2 100644 --- a/ext/fg/js/frontend-api-sender.js +++ b/ext/fg/js/frontend-api-sender.js @@ -31,7 +31,7 @@ class FrontendApiSender { invoke(action, params, target) { if (this.disconnected) { - return Promise.reject('Disconnected'); + return Promise.reject(new Error('Disconnected')); } if (this.port === null) { @@ -110,8 +110,8 @@ class FrontendApiSender { clearTimeout(info.timer); info.timer = null; - if (typeof data.error === 'string') { - info.reject(data.error); + if (typeof data.error !== 'undefined') { + info.reject(jsonToError(data.error)); } else { info.resolve(data.result); } @@ -122,7 +122,7 @@ class FrontendApiSender { const info = this.callbacks[id]; delete this.callbacks[id]; info.timer = null; - info.reject(reason); + info.reject(new Error(reason)); } static generateId(length) { diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js index 99b28549..efbd28b2 100644 --- a/ext/fg/js/popup-proxy.js +++ b/ext/fg/js/popup-proxy.js @@ -98,7 +98,7 @@ class PopupProxy { invokeHostApi(action, params={}) { if (typeof this.parentFrameId !== 'number') { - return Promise.reject('Invalid frame'); + return Promise.reject(new Error('Invalid frame')); } return this.apiSender.invoke(action, params, `popup-proxy-host#${this.parentFrameId}`); } diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index dc99274e..9a7968a7 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -30,19 +30,19 @@ function utilInvoke(action, params={}) { chrome.runtime.sendMessage(data, (response) => { utilCheckLastError(chrome.runtime.lastError); if (response !== null && typeof response === 'object') { - if (response.error) { - reject(response.error); + if (typeof response.error !== 'undefined') { + reject(jsonToError(response.error)); } else { resolve(response.result); } } else { const message = response === null ? 'Unexpected null response' : `Unexpected response of type ${typeof response}`; - reject(`${message} (${JSON.stringify(data)})`); + reject(new Error(`${message} (${JSON.stringify(data)})`)); } }); } catch (e) { window.yomichan_orphaned = true; - reject(e.message); + reject(e); } }); } |