Throw Response from apiJson so API 404s render as 404 pages

apiJson was throwing a plain Error on non-ok responses, which React
Router always treated as a 500. Now throws a Response with the actual
status code so API 404s surface as proper 404 error pages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-03-02 11:05:34 -05:00
parent fcba787cd5
commit e938d3395a

View file

@ -51,6 +51,6 @@ export async function apiFetch(
*/
export async function apiJson<T>(path: string, init?: RequestInit): Promise<T> {
const res = await apiFetch(path, init);
if (!res.ok) throw new Error(`API ${res.status}: ${await res.text()}`);
if (!res.ok) throw new Response(await res.text(), { status: res.status });
return res.json() as Promise<T>;
}