diff options
Diffstat (limited to 'ext/js/display/display-anki.js')
-rw-r--r-- | ext/js/display/display-anki.js | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js index 759998c4..77ba7ffb 100644 --- a/ext/js/display/display-anki.js +++ b/ext/js/display/display-anki.js @@ -17,6 +17,7 @@ */ import {EventListenerCollection, deferPromise} from '../core.js'; +import {toError} from '../core/to-error.js'; import {AnkiNoteBuilder} from '../data/anki-note-builder.js'; import {AnkiUtil} from '../data/anki-util.js'; import {PopupMenu} from '../dom/popup-menu.js'; @@ -159,7 +160,7 @@ export class DisplayAnki { try { ({note: note, errors, requirements} = await this._createNote(dictionaryEntry, mode, [])); } catch (e) { - errors = [e instanceof Error ? e : new Error(`${e}`)]; + errors = [toError(e)]; } /** @type {import('display-anki').AnkiNoteLogData} */ const entry = {mode, note}; @@ -174,7 +175,7 @@ export class DisplayAnki { return { ankiNoteData, - ankiNoteDataException: ankiNoteDataException instanceof Error ? ankiNoteDataException : new Error(`${ankiNoteDataException}`), + ankiNoteDataException: toError(ankiNoteDataException), ankiNotes }; } @@ -490,7 +491,7 @@ export class DisplayAnki { addNoteOkay = true; } catch (e) { allErrors.length = 0; - allErrors.push(e instanceof Error ? e : new Error(`${e}`)); + allErrors.push(toError(e)); } if (addNoteOkay) { @@ -501,7 +502,7 @@ export class DisplayAnki { try { await yomitan.api.suspendAnkiCardsForNote(noteId); } catch (e) { - allErrors.push(e instanceof Error ? e : new Error(`${e}`)); + allErrors.push(toError(e)); } } button.disabled = true; @@ -509,7 +510,7 @@ export class DisplayAnki { } } } catch (e) { - allErrors.push(e instanceof Error ? e : new Error(`${e}`)); + allErrors.push(toError(e)); } finally { progressIndicatorVisible.clearOverride(overrideToken); } @@ -647,7 +648,7 @@ export class DisplayAnki { } } catch (e) { infos = this._getAnkiNoteInfoForceValue(notes, false); - ankiError = e instanceof Error ? e : new Error(`${e}`); + ankiError = toError(e); } /** @type {import('display-anki').DictionaryEntryDetails[]} */ @@ -855,11 +856,11 @@ export class DisplayAnki { await yomitan.api.noteView(noteIds[0], this._noteGuiMode, false); } catch (e) { const displayErrors = ( - e instanceof Error && e.message === 'Mode not supported' ? + toError(e).message === 'Mode not supported' ? [this._display.displayGenerator.instantiateTemplateFragment('footer-notification-anki-view-note-error')] : void 0 ); - this._showErrorNotification([e instanceof Error ? e : new Error(`${e}`)], displayErrors); + this._showErrorNotification([toError(e)], displayErrors); return; } } |