From 4e446634ca0fe8e49fd38ae7d5f001f84efd228f Mon Sep 17 00:00:00 2001 From: Rayan Salhab Date: Fri, 27 Mar 2026 07:16:21 +0000 Subject: [PATCH] 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 --- apps/web/components/memories-grid.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/web/components/memories-grid.tsx b/apps/web/components/memories-grid.tsx index cc7e8453..e58ea203 100644 --- a/apps/web/components/memories-grid.tsx +++ b/apps/web/components/memories-grid.tsx @@ -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,