fix: let AbortError propagate through the API client

The network-error wrapping added in the error-boundary work also caught
deliberate AbortController cancellations and turned them into a network_error
ApiError, breaking callers that distinguish "cancelled" from "failed" (the
cancellable admin fetches). Rethrow DOMException AbortError unchanged; only
genuine network failures become ApiError(status 0).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-07-11 15:25:01 +02:00
parent ba3e5b481b
commit 0afd202164
2 changed files with 11 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "mangalord-frontend",
"version": "0.128.2",
"version": "0.128.3",
"private": true,
"type": "module",
"scripts": {

View File

@@ -106,12 +106,16 @@ export async function request<T>(
let res: Response;
try {
res = await fetch(`${BASE}${path}`, { credentials: 'include', ...init });
} catch {
// A network-level failure (connection refused, DNS, offline, blocked by
// CORS) rejects `fetch` with a bare TypeError instead of returning a
// response. Normalise it to an ApiError (status 0 = "no response reached
// us") so callers and SvelteKit load functions handle it uniformly
// instead of crashing on an unexpected TypeError.
} catch (e) {
// A deliberate cancellation (AbortController) must propagate unchanged so
// callers can tell "cancelled" from "network failure" (e.g. the
// cancellable admin fetches treat AbortError as a no-op).
if (e instanceof DOMException && e.name === 'AbortError') throw e;
// Any other rejection is a network-level failure (connection refused,
// DNS, offline, blocked by CORS): `fetch` rejects with a bare TypeError
// instead of returning a response. Normalise it to an ApiError (status 0
// = "no response reached us") so callers and SvelteKit load functions
// handle it uniformly instead of crashing on an unexpected TypeError.
throw new ApiError(
0,
'network_error',