export async function handleResponse(response: Response, extract: (data: unknown) => T): Promise { if (!response.ok) { const body = (await response.json().catch(() => null)) as null | { error?: string }; throw new Error(body?.error ?? `HTTP ${response.status}`); } const data: unknown = await response.json(); return extract(data); } export async function handleVoidResponse(response: Response): Promise { if (!response.ok) { const body = (await response.json().catch(() => null)) as null | { error?: string }; throw new Error(body?.error ?? `HTTP ${response.status}`); } }