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