mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-11 22:51:05 +00:00
fix: handle invalid JSON response in facets query
Add validation for facets API response to prevent JSON parse errors when the server returns unexpected data. Falls back to empty facets and zero total when response is invalid. Fixes #802
This commit is contained in:
parent
57748ead4d
commit
4e446634ca
1 changed files with 15 additions and 1 deletions
|
|
@ -156,7 +156,21 @@ export function MemoriesGrid({
|
|||
throw new Error(response.error?.message || "Failed to fetch facets")
|
||||
}
|
||||
|
||||
return response.data as FacetsResponse
|
||||
// Validate response data to prevent JSON parse errors
|
||||
const data = response.data as unknown
|
||||
if (
|
||||
data &&
|
||||
typeof data === "object" &&
|
||||
"facets" in data &&
|
||||
Array.isArray(data.facets) &&
|
||||
"total" in data &&
|
||||
typeof data.total === "number"
|
||||
) {
|
||||
return data as FacetsResponse
|
||||
}
|
||||
|
||||
// Return default values if response is invalid
|
||||
return { facets: [], total: 0 }
|
||||
},
|
||||
staleTime: 5 * 60 * 1000,
|
||||
enabled: !!user,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue