async function handle_fetch(promise) { const result = await promise; const json = await result.json(); if (!result.ok) { throw json; } return json; } export function get(url) { return handle_fetch(fetch(url)); } export function post(url, body) { return handle_fetch(fetch(url, { method: 'POST', body: JSON.stringify(body), })); }