export async function handleFetch(url: string, args?: RequestInit) { const response = await fetch(url, args) if (!response.ok) { throw new Error( `HTTP ${response.status} fetching ${url} ${await response.text()}`, ) } return response } export async function textfetch(url: string, args?: RequestInit) { const response = await handleFetch(url, args) return response.text() } export async function jsonfetch(url: string, args?: RequestInit) { const response = await handleFetch(url, args) return response.json() as Promise } export function timeout(time: number) { return new Promise(res => setTimeout(res, time)) }