From 3adfa3f17c191b361b0051d46c74a7524bc0cdd6 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 4 May 2026 22:29:27 +0200 Subject: [PATCH] Add errorName helper, use it instead of (err as Error).name Mirrors errorMessage in web_src/js/modules/errors.ts. Migrates the only two existing `(err as Error).name !== 'AbortError'` sites (modules/search.ts, features/common-fetch-action.ts). Co-Authored-By: Claude (Opus 4.7) --- web_src/js/features/common-fetch-action.ts | 4 ++-- web_src/js/modules/errors.ts | 4 ++++ web_src/js/modules/search.ts | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/web_src/js/features/common-fetch-action.ts b/web_src/js/features/common-fetch-action.ts index 96bc2e2adb..0f65f780ac 100644 --- a/web_src/js/features/common-fetch-action.ts +++ b/web_src/js/features/common-fetch-action.ts @@ -1,7 +1,7 @@ import {GET, request} from '../modules/fetch.ts'; import {hideToastsAll, showErrorToast} from '../modules/toast.ts'; import {addDelegatedEventListener, createElementFromHTML} from '../utils/dom.ts'; -import {errorMessage} from '../modules/errors.ts'; +import {errorMessage, errorName} from '../modules/errors.ts'; import {confirmModal, createConfirmModal} from './comp/ConfirmModal.ts'; import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts'; import {registerGlobalSelectorFunc} from '../modules/observer.ts'; @@ -138,7 +138,7 @@ async function performActionRequest(el: HTMLElement, opt: FetchActionOpts) { } await handleFetchActionError(resp); } catch (err) { - if ((err as Error).name !== 'AbortError') { + if (errorName(err) !== 'AbortError') { console.error(`Fetch action request error:`, err); showErrorToast(`Error: ${errorMessage(err)}`); } diff --git a/web_src/js/modules/errors.ts b/web_src/js/modules/errors.ts index d4fb549cfe..95a171693a 100644 --- a/web_src/js/modules/errors.ts +++ b/web_src/js/modules/errors.ts @@ -6,6 +6,10 @@ export function errorMessage(err: unknown): string { return (err as Error)?.message || String(err); } +export function errorName(err: unknown): string { + return (err as Error)?.name ?? ''; +} + export function showGlobalErrorMessage(msg: string, msgType: Intent = 'error', details?: string) { const parentContainer = document.querySelector('.page-content') ?? document.body; if (!parentContainer) { diff --git a/web_src/js/modules/search.ts b/web_src/js/modules/search.ts index 9121dae194..258d3c3c5b 100644 --- a/web_src/js/modules/search.ts +++ b/web_src/js/modules/search.ts @@ -1,5 +1,6 @@ import {debounce} from 'throttle-debounce'; import {GET} from './fetch.ts'; +import {errorName} from './errors.ts'; import {html, htmlRaw} from '../utils/html.ts'; import {urlQueryEscape} from '../utils/url.ts'; @@ -73,7 +74,7 @@ export function attachSearchBox(container: HTMLElement, url: string // only render if the fetch wasn't aborted (e.g. by hide()) and the input still matches if (!ctrl.signal.aborted && input.value === query) render(results); } catch (err) { - if ((err as Error).name !== 'AbortError') hide(); + if (errorName(err) !== 'AbortError') hide(); } });