diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-07-09 20:26:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-09 20:26:20 -0400 |
commit | d897fb553d5f9901bf2c8a0942e87e043788e1b2 (patch) | |
tree | 6343c627a134fc2699b5b3e5d8c95ac5ce1f0a91 /ext/js/display/display-anki.js | |
parent | 7a1570885e7310e5b1e15ab798c9eb66694a96fb (diff) |
Improve error when card has missing content (#1818)
Diffstat (limited to 'ext/js/display/display-anki.js')
-rw-r--r-- | ext/js/display/display-anki.js | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js index 235149ad..b08dc952 100644 --- a/ext/js/display/display-anki.js +++ b/ext/js/display/display-anki.js @@ -368,12 +368,8 @@ class DisplayAnki { const {note, errors, requirements: outputRequirements} = await this._createNote(dictionaryEntry, mode, requirements); allErrors.push(...errors); - if (outputRequirements.length > 0) { - const error = new Error('The created card may not have some content'); - error.requirements = requirements; - error.outputRequirements = outputRequirements; - allErrors.push(error); - } + const error = this._getAddNoteRequirementsError(requirements, outputRequirements); + if (error !== null) { allErrors.push(error); } let noteId = null; let addNoteOkay = false; @@ -413,6 +409,29 @@ class DisplayAnki { } } + _getAddNoteRequirementsError(requirements, outputRequirements) { + if (outputRequirements.length === 0) { return null; } + + let count = 0; + for (const requirement of outputRequirements) { + const {type} = requirement; + switch (type) { + case 'audio': + case 'clipboardImage': + break; + default: + ++count; + break; + } + } + if (count === 0) { return null; } + + const error = new Error('The created card may not have some content'); + error.requirements = requirements; + error.outputRequirements = outputRequirements; + return error; + } + _showAnkiNoteErrors(errors) { if (this._ankiNoteNotificationEventListeners !== null) { this._ankiNoteNotificationEventListeners.removeAllEventListeners(); |