diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-04-12 12:43:24 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-04-12 12:43:32 -0400 |
commit | 3c335e68cdd41860d791ffe85dd07abf8932d3ce (patch) | |
tree | 393017e01874632f46168986492996853445fb19 /ext/bg/js | |
parent | cc5e4294223f9d0106ddec1d561b29ac449b1115 (diff) |
Throw errors in returned by invocation
Diffstat (limited to 'ext/bg/js')
-rw-r--r-- | ext/bg/js/anki.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index 27590311..c07af462 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -81,7 +81,7 @@ class AnkiConnect { async storeMediaFile(filename, dataBase64) { if (!this._enabled) { - return {result: null, error: 'AnkiConnect not enabled'}; + throw new Error('AnkiConnect not enabled'); } await this._checkVersion(); return await this._ankiInvoke('storeMediaFile', {filename, data: dataBase64}); @@ -110,8 +110,19 @@ class AnkiConnect { } } - _ankiInvoke(action, params) { - return requestJson(this._server, 'POST', {action, params, version: this._localVersion}); + async _ankiInvoke(action, params) { + const result = await requestJson(this._server, 'POST', {action, params, version: this._localVersion}); + if ( + result !== null && + typeof result === 'object' && + !Array.isArray(result) + ) { + const error = result.error; + if (typeof error !== 'undefined') { + throw new Error(`AnkiConnect error: ${error}`); + } + } + return result; } _escapeQuery(text) { |