summaryrefslogtreecommitdiff
path: root/ext/js/display
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/display')
-rw-r--r--ext/js/display/display-anki.js17
-rw-r--r--ext/js/display/display.js5
-rw-r--r--ext/js/display/option-toggle-hotkey-handler.js3
3 files changed, 14 insertions, 11 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;
}
}
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index ff77d203..7e7dd426 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -21,6 +21,7 @@ import {FrameEndpoint} from '../comm/frame-endpoint.js';
import {DynamicProperty, EventDispatcher, EventListenerCollection, clone, deepEqual, log, promiseTimeout} from '../core.js';
import {extendApiMap, invokeApiMapHandler} from '../core/api-map.js';
import {ExtensionError} from '../core/extension-error.js';
+import {toError} from '../core/to-error.js';
import {PopupMenu} from '../dom/popup-menu.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
import {ScrollElement} from '../dom/scroll-element.js';
@@ -787,7 +788,7 @@ export class Display extends EventDispatcher {
break;
}
} catch (e) {
- this.onError(e instanceof Error ? e : new Error(`${e}`));
+ this.onError(toError(e));
}
}
@@ -922,7 +923,7 @@ export class Display extends EventDispatcher {
};
this.setContent(details);
} catch (error) {
- this.onError(error instanceof Error ? error : new Error(`${error}`));
+ this.onError(toError(error));
}
}
diff --git a/ext/js/display/option-toggle-hotkey-handler.js b/ext/js/display/option-toggle-hotkey-handler.js
index 73c92d59..ba4c8578 100644
--- a/ext/js/display/option-toggle-hotkey-handler.js
+++ b/ext/js/display/option-toggle-hotkey-handler.js
@@ -18,6 +18,7 @@
import {generateId} from '../core.js';
import {ExtensionError} from '../core/extension-error.js';
+import {toError} from '../core/to-error.js';
import {yomitan} from '../yomitan.js';
export class OptionToggleHotkeyHandler {
@@ -132,7 +133,7 @@ export class OptionToggleHotkeyHandler {
* @returns {DocumentFragment}
*/
_createErrorMessage(path, error) {
- const message = error instanceof Error ? error.message : `${error}`;
+ const message = toError(error).message;
const fragment = document.createDocumentFragment();
const n1 = document.createElement('em');
n1.textContent = path;