File size: 698 Bytes
c816150 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /**
* The reason a non-OK response gives, as one line for the screen.
*
* Every backend error body carries `error` (backend/main.py wraps each
* HTTPException in the same envelope); a refusal for a retired module also
* carries `reason` (410 DISEASE_RETIRED). Anything else falls back to the
* HTTP status text, so a failure is never shown as nothing at all.
*/
export async function responseError(res) {
let body = {};
try {
body = await res.json();
} catch {
// not JSON
}
const main = body?.error
|| (typeof body?.detail === 'string' ? body.detail : null)
|| res.statusText
|| `HTTP ${res.status}`;
return body?.reason ? `${main} ${body.reason}` : main;
}
|