server: generic 500s, fix duplicate/invalid-id error handling

All admin API error responses (and the global error handler) now emit
RFC 7807 application/problem+json bodies (type/title/status/detail)
instead of the ad hoc { error: string } shape, per review feedback on
this PR. Scoped to admin.ts + the global handler in index.ts, since
that's what this PR already touches; public.ts's routes still use the
old shape pending a follow-up.
This commit is contained in:
iris 2026-07-29 20:22:31 +02:00
commit 59eb54d9fb
4 changed files with 148 additions and 35 deletions

View file

@ -7,10 +7,14 @@ async function j<T = any>(res: Response): Promise<T> {
return res.json();
}
// Best-effort error message from a failed response ({ error } JSON or status text).
// Best-effort error message from a failed response. Prefers RFC 7807
// (application/problem+json) `detail`/`title` — what the admin routes send
// — falls back to the older ad hoc `{ error }` shape (still used by a few
// not-yet-converted endpoints), then plain status text.
async function errText(res: Response): Promise<string> {
try {
return (await res.json()).error ?? res.statusText;
const body = await res.json();
return body.detail ?? body.title ?? body.error ?? res.statusText;
} catch {
return res.statusText;
}