From 899500249ed5753ecbed8ad0936d64ce732fb252 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Mon, 2 Feb 2026 17:04:18 +0530 Subject: [PATCH] Fix UI data loading: Orval fetcher returns {data,status,headers} --- frontend/src/api/mutator.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/api/mutator.ts b/frontend/src/api/mutator.ts index fbe9ae6a..24cf9d13 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; }