export function postJson(path, payload) { return fetch(path, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); } export async function fetchJson(path) { const response = await fetch(path); const body = await response.json(); if (!response.ok) { throw new Error(body?.error || `Request failed: ${response.status}`); } return body; } export async function postJsonResult(path, payload) { const response = await postJson(path, payload); const body = await response.json(); if (!response.ok || body?.ok === false) { throw new Error(body?.error || `Request failed: ${response.status}`); } return body; }