aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-08-18 21:14:09 -0700
committerAlex Yatskov <alex@foosoft.net>2017-08-18 21:14:09 -0700
commit30fe3d250646e0993cc49a7ef6b783eee206d043 (patch)
treec9d744ce3290005775dc8e9da08c79f8518c96af /ext/bg/js/api.js
parent922d2cd468ec1d05fc4d68f60419a6af11aa5c94 (diff)
fix anki network error dialog on search page, cleanup template
workaround
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js31
1 files changed, 19 insertions, 12 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 2afe82a0..4676e2dc 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -66,22 +66,29 @@ async function apiDefinitionAdd(definition, mode) {
}
async function apiDefinitionsAddable(definitions, modes) {
- const notes = [];
- for (const definition of definitions) {
- for (const mode of modes) {
- notes.push(dictNoteFormat(definition, mode, utilBackend().options));
+ const states = [];
+
+ try {
+ const notes = [];
+ for (const definition of definitions) {
+ for (const mode of modes) {
+ notes.push(dictNoteFormat(definition, mode, utilBackend().options));
+ }
}
- }
- const results = await utilBackend().anki.canAddNotes(notes);
- const states = [];
- for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
- const state = {};
- for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
- state[modes[modeOffset]] = results[resultBase + modeOffset];
+ const results = await utilBackend().anki.canAddNotes(notes);
+ for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
+ const state = {};
+ for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
+ state[modes[modeOffset]] = results[resultBase + modeOffset];
+ }
+
+ states.push(state);
}
- states.push(state);
+ return states;
+ } catch (e) {
+ // NOP
}
return states;