aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display/display-anki.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-01-15 06:12:33 -0500
committerGitHub <noreply@github.com>2024-01-15 11:12:33 +0000
commit48f1d012ad5045319d4e492dfbefa39da92817b2 (patch)
tree51b5b53a7b1192f04a8292c3a9aa0f5063c64b46 /ext/js/display/display-anki.js
parent9cfa20cbd2289d82a5abf05a2e5ea8af5016222c (diff)
Add toError utility function (#523)
* Add asError utility function * Rename to toError
Diffstat (limited to 'ext/js/display/display-anki.js')
-rw-r--r--ext/js/display/display-anki.js17
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;
}
}