diff --git a/frontend/src/api/mutator.ts b/frontend/src/api/mutator.ts index fbe9ae6..24cf9d1 100644 --- a/frontend/src/api/mutator.ts +++ b/frontend/src/api/mutator.ts @@ -1,4 +1,3 @@ - function getActorId(): string | undefined { if (typeof window !== "undefined") { const stored = window.localStorage.getItem("actor_employee_id"); @@ -12,6 +11,11 @@ function getActorId(): string | undefined { } return process.env.NEXT_PUBLIC_ACTOR_EMPLOYEE_ID; } + +/** + * Orval-generated client expects the fetcher to return an object like: + * { data: , status: , headers: Headers } + */ export async function customFetch( url: string, options: RequestInit, @@ -28,10 +32,13 @@ export async function customFetch( }, }); + const text = await res.text().catch(() => ""); + if (!res.ok) { - const text = await res.text().catch(() => ""); throw new Error(`${res.status} ${res.statusText}${text ? `: ${text}` : ""}`); } - return (await res.json()) as T; + const json = text ? JSON.parse(text) : null; + // Match the types generated by Orval (status + headers + data) + return ({ data: json, status: res.status, headers: res.headers } as unknown) as T; }