export async function getResponseError(r: Response): Promise { let ct = r.headers.get("Content-Type"); if (ct && ct.indexOf("json") > -1) { const json = await r.json(); if (json.error) { return json.error; } } const html = await r.text(); if (html) { const doc = new DOMParser().parseFromString(html, "text/html"); return doc.documentElement.textContent ?? ""; } else { return r.statusText; } }