async function handleResponse(res: Response): Promise { if (!res.ok) { const body = await res.json().catch(() => ({ message: res.statusText })) as { message?: string }; throw new Error(body.message ?? `HTTP ${res.status}`); } return res.json() as Promise; } export const api = { get: (url: string) => fetch(url, { cache: 'no-store' }).then((r) => handleResponse(r)), post: (url: string, body?: unknown) => fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: body !== undefined ? JSON.stringify(body) : undefined, }).then((r) => handleResponse(r)), patch: (url: string, body: unknown) => fetch(url, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }).then((r) => handleResponse(r)), del: (url: string) => fetch(url, { method: 'DELETE' }).then((r) => handleResponse(r)), };