fix: null guard on API array responses to prevent crash

This commit is contained in:
2026-07-06 08:51:59 -04:00
parent 50ed8abe95
commit 238ca23d5b
3 changed files with 27 additions and 22 deletions
+5 -2
View File
@@ -146,9 +146,12 @@ async function request<T>(method: string, path: string, body?: unknown): Promise
return undefined as T;
}
const text = await res.text();
const data = text ? JSON.parse(text) : {};
if (!text) {
throw new ApiError(res.status, "empty response");
}
const data = JSON.parse(text);
if (!res.ok) {
throw new ApiError(res.status, data.error || res.statusText);
throw new ApiError(res.status, (data && data.error) || res.statusText);
}
return data as T;
}