A small reusable wrapper that handles HTTP failures and parses JSON.
async function fetchJson<T>(url: string): Promise<T> {
const response = await fetch(url);
if (!response.ok) {
throw new Error('HTTP ' + response.status);
}
return (await response.json()) as T;
}