0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-11 04:55:34 +02:00

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) <noreply@anthropic.com>
This commit is contained in:
silverwind 2026-05-04 22:29:27 +02:00
parent 92158b1ee5
commit 3adfa3f17c
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
3 changed files with 8 additions and 3 deletions

View File

@ -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)}`);
}

View File

@ -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) {

View File

@ -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<T = unknown>(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();
}
});