export async function getJSON(url) { const r = await fetch(url); if (!r.ok) throw new Error((await r.text().catch(() => '')) || r.statusText); return r.json(); } export async function postJSON(url, body) { const r = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body ?? {}), credentials: 'same-origin', // send/receive the session cookie }); if (!r.ok) { let msg = r.statusText; try { const j = await r.json(); if (j && j.detail) msg = j.detail; } catch { /* non-JSON error body */ } throw new Error(msg); } return r.json(); }