export async function apiFetch(path: string, init?: RequestInit): Promise { const res = await fetch(path, { ...init, credentials: "include", headers: { "Content-Type": "application/json", ...init?.headers } }); if (!res.ok) { const body = await res.json().catch(() => ({})); throw new Error(body.error ?? `Request failed (${res.status})`); } if (res.status === 204) { return undefined as T; } return (await res.json()) as T; }