Better error rendering

This commit is contained in:
Jack Kingsman
2026-01-17 21:53:51 -08:00
parent 74f2e8556d
commit 7c778885f6
5 changed files with 16 additions and 6 deletions
+12 -2
View File
@@ -26,8 +26,18 @@ async function fetchJson<T>(url: string, options?: RequestInit): Promise<T> {
},
});
if (!res.ok) {
const error = await res.text();
throw new Error(error || res.statusText);
const errorText = await res.text();
// FastAPI returns errors as {"detail": "message"}, extract the message
let errorMessage = errorText || res.statusText;
try {
const errorJson = JSON.parse(errorText);
if (errorJson.detail) {
errorMessage = errorJson.detail;
}
} catch {
// Not JSON, use raw text
}
throw new Error(errorMessage);
}
return res.json();
}