fix: null guard on API array responses to prevent crash
This commit is contained in:
+5
-2
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user