summaryrefslogtreecommitdiff
path: root/ext/bg/js/settings/anki-templates-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-30 12:33:29 -0500
committerGitHub <noreply@github.com>2021-01-30 12:33:29 -0500
commitd0b8b605db93c51b5ce2501a482c57432b45bfa6 (patch)
treec42bf4f59d7945c8b9c42cd0677e3827d326a71a /ext/bg/js/settings/anki-templates-controller.js
parentaf6e9a8153c24d0400592005b31d56fecff67068 (diff)
Add note errors (#1329)
* Update _addAnkiNote to track errors * Change comparison * Update anki note adding to show errors * Fix template * Show errors when Anki card creation behaves unexpectedly * Update some errors related to anki media injection * Update addAnkiNote error handling * Improve Anki errors * Simplify error messages related to template rendering
Diffstat (limited to 'ext/bg/js/settings/anki-templates-controller.js')
-rw-r--r--ext/bg/js/settings/anki-templates-controller.js32
1 files changed, 24 insertions, 8 deletions
diff --git a/ext/bg/js/settings/anki-templates-controller.js b/ext/bg/js/settings/anki-templates-controller.js
index 125d8e16..31bd1e92 100644
--- a/ext/bg/js/settings/anki-templates-controller.js
+++ b/ext/bg/js/settings/anki-templates-controller.js
@@ -165,7 +165,7 @@ class AnkiTemplatesController {
async _validate(infoNode, field, mode, showSuccessResult, invalidateInput) {
const text = this._renderTextInput.value || '';
- const exceptions = [];
+ const errors = [];
let result = `No definition found for ${text}`;
try {
const optionsContext = this._settingsController.getOptionsContext();
@@ -193,20 +193,36 @@ class AnkiTemplatesController {
resultOutputMode,
glossaryLayoutMode,
compactTags,
- errors: exceptions
+ errors
});
result = note.fields.field;
}
} catch (e) {
- exceptions.push(e);
+ errors.push(e);
}
- const hasException = exceptions.length > 0;
- infoNode.hidden = !(showSuccessResult || hasException);
- infoNode.textContent = hasException ? exceptions.map((e) => `${e}`).join('\n') : (showSuccessResult ? result : '');
- infoNode.classList.toggle('text-danger', hasException);
+ const errorToMessageString = (e) => {
+ if (isObject(e)) {
+ let v = e.data;
+ if (isObject(v)) {
+ v = v.error;
+ if (isObject(v)) {
+ e = v;
+ }
+ }
+
+ v = e.message;
+ if (typeof v === 'string') { return v; }
+ }
+ return `${e}`;
+ };
+
+ const hasError = errors.length > 0;
+ infoNode.hidden = !(showSuccessResult || hasError);
+ infoNode.textContent = hasError ? errors.map(errorToMessageString).join('\n') : (showSuccessResult ? result : '');
+ infoNode.classList.toggle('text-danger', hasError);
if (invalidateInput) {
- this._fieldTemplatesTextarea.dataset.invalid = `${hasException}`;
+ this._fieldTemplatesTextarea.dataset.invalid = `${hasError}`;
}
}
}