fix(renderer): avoid non-iterable provider data
This commit is contained in:
@@ -89,15 +89,33 @@ function parseUnifiedProxyResponse<T>(
|
||||
}
|
||||
|
||||
const data: HostApiProxyData = response.data ?? {};
|
||||
const status = data.status ?? 200;
|
||||
const ok = typeof data.ok === 'boolean'
|
||||
? data.ok
|
||||
: status >= 200 && status < 300;
|
||||
|
||||
trackUiEvent('hostapi.fetch', {
|
||||
path,
|
||||
method,
|
||||
source: 'ipc-proxy',
|
||||
durationMs: Date.now() - startedAt,
|
||||
status: data.status ?? 200,
|
||||
status,
|
||||
});
|
||||
|
||||
if (data.status === 204) return undefined as T;
|
||||
if (!ok) {
|
||||
const json = data.json;
|
||||
const message = (json && typeof json === 'object' && 'error' in (json as Record<string, unknown>))
|
||||
? String((json as Record<string, unknown>).error)
|
||||
: (typeof json === 'string' && json.trim() ? json : (data.text || `HTTP ${status}`));
|
||||
throw normalizeAppError(new Error(message), {
|
||||
source: 'ipc-proxy',
|
||||
path,
|
||||
method,
|
||||
status,
|
||||
});
|
||||
}
|
||||
|
||||
if (status === 204) return undefined as T;
|
||||
if (data.json !== undefined) return data.json as T;
|
||||
return data.text as T;
|
||||
}
|
||||
|
||||
@@ -77,13 +77,13 @@ export function ChatToolbar() {
|
||||
|
||||
const providerVendorById = useMemo(() => {
|
||||
const map = new Map<string, ProviderVendorInfo>();
|
||||
for (const v of providerVendors) map.set(v.id, v);
|
||||
for (const v of (Array.isArray(providerVendors) ? providerVendors : [])) map.set(v.id, v);
|
||||
return map;
|
||||
}, [providerVendors]);
|
||||
|
||||
const providerStatusById = useMemo(() => {
|
||||
const map = new Map<string, ProviderWithKeyInfo>();
|
||||
for (const s of providerStatuses) map.set(s.id, s);
|
||||
for (const s of (Array.isArray(providerStatuses) ? providerStatuses : [])) map.set(s.id, s);
|
||||
return map;
|
||||
}, [providerStatuses]);
|
||||
|
||||
|
||||
@@ -88,9 +88,9 @@ export const useProviderStore = create<ProviderState>((set, get) => ({
|
||||
const snapshot = await fetchProviderSnapshot();
|
||||
|
||||
set({
|
||||
statuses: snapshot.statuses ?? [],
|
||||
accounts: snapshot.accounts ?? [],
|
||||
vendors: snapshot.vendors ?? [],
|
||||
statuses: Array.isArray(snapshot.statuses) ? snapshot.statuses : [],
|
||||
accounts: Array.isArray(snapshot.accounts) ? snapshot.accounts : [],
|
||||
vendors: Array.isArray(snapshot.vendors) ? snapshot.vendors : [],
|
||||
defaultAccountId: snapshot.defaultAccountId ?? null,
|
||||
loading: false
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user