Spaces:
Sleeping

omnidiag / frontend /src /utils /apiError.js
yahyoha's picture
Claude Opus 5.5
Release: retire BRFSS diabetes (source deploy/v2-platform 8bbbfe9)
c816150
Raw History Blame Contribute Delete
698 Bytes
/**
* 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;
}