feat: harden runtime readiness and session workflow
This commit is contained in:
@@ -12,7 +12,11 @@ export async function apiFetch<T>(path: string, init?: RequestInit): Promise<T>
|
||||
}
|
||||
const res = await fetch(joinBackendPath(BASE, path), { ...init, headers });
|
||||
if (!res.ok) throw new Error(`${res.status} ${await res.text().catch(() => "")}`);
|
||||
return res.status === 204 ? (undefined as T) : ((await res.json()) as T);
|
||||
if (res.status === 204) return undefined as T;
|
||||
// Accepted fire-and-forget endpoints may legitimately return 202 with no
|
||||
// representation. Keep apiFetch useful for both 202 and 204 contracts.
|
||||
const body = await res.text();
|
||||
return body ? (JSON.parse(body) as T) : (undefined as T);
|
||||
}
|
||||
|
||||
export { BASE };
|
||||
|
||||
Reference in New Issue
Block a user