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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -13,7 +13,7 @@
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="manifest" href="/site.webmanifest" />
<script type="module" crossorigin src="/assets/index-Z2aWr4hK.js"></script>
<script type="module" crossorigin src="/assets/index-Djay-rUY.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BpFnqQF8.css">
</head>
<body>
+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();
}