Fix UI data loading: Orval fetcher returns {data,status,headers}
This commit is contained in:
@@ -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: <json>, status: <number>, headers: Headers }
|
||||
*/
|
||||
export async function customFetch<T>(
|
||||
url: string,
|
||||
options: RequestInit,
|
||||
@@ -28,10 +32,13 @@ export async function customFetch<T>(
|
||||
},
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user