From 238320b015c1bc5e710ba88f61cb63f94a03c2ed Mon Sep 17 00:00:00 2001 From: Guillermo Pages Date: Mon, 24 Nov 2025 10:47:09 +0100 Subject: [PATCH] fix: handle Flask API response wrapper format Fix TypeError: t.map is not a function on Plans and Members pages Issue: Backend wraps responses in { status: 'success', data: {...} } but frontend was expecting direct data. Changes: - Update handleApiResponse to extract data from Flask wrapper - Special handling for policy endpoint (returns { policy: {...} }) - Handles both wrapped and unwrapped responses for compatibility Fixes the 'Application error' on Plans and Members pages. --- src/lib/api/facility-admin.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/api/facility-admin.ts b/src/lib/api/facility-admin.ts index fbff788..ea79a26 100644 --- a/src/lib/api/facility-admin.ts +++ b/src/lib/api/facility-admin.ts @@ -29,10 +29,14 @@ import apiFetch from '@/src/utils/apiFetch'; /** * Handle API response + * Flask backend wraps responses in: { status: 'success'|'fail', data: {...} } */ async function handleApiResponse(response: Response): Promise> { if (response.ok) { - const data = await response.json(); + const json = await response.json(); + // Flask returns { status: 'success', data: {...} } + // Extract the actual data from the wrapper + const data = json.data !== undefined ? json.data : json; return { success: true, data }; } @@ -529,7 +533,15 @@ export async function getPolicy( headers: { 'Content-Type': 'application/json' }, }); - return handleApiResponse(response); + const result = await handleApiResponse(response); + + // Backend returns { status: 'success', data: { policy: {...} } } + // Extract the policy object + if (result.success && result.data.policy) { + return { success: true, data: result.data.policy }; + } + + return result as FacilityAdminApiResult; } catch (error) { return { success: false,