From 22f63a10b481d2d7ec02329b6e4acb66189cea2e Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 14 Oct 2025 03:29:22 +0000 Subject: [PATCH] Normalize errors in listProfiles cgen-7c37ffdfc7a6413db03baa09beafcf2d --- client/lib/aethex-database-adapter.ts | 38 +++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/client/lib/aethex-database-adapter.ts b/client/lib/aethex-database-adapter.ts index 717e8714..be756bc2 100644 --- a/client/lib/aethex-database-adapter.ts +++ b/client/lib/aethex-database-adapter.ts @@ -362,26 +362,36 @@ export const aethexUserService = { async listProfiles(limit = 50): Promise { ensureSupabase(); - const { data, error } = await supabase - .from("user_profiles") - .select( - ` + let data: any[] | null = null; + try { + const resp = await supabase + .from("user_profiles") + .select( + ` *, user_achievements ( achievements ( xp_reward ) ) `, - ) - .order("updated_at", { ascending: false }) - .limit(limit); - - if (error) { - if (isTableMissing(error)) { - throw new Error( - 'Supabase table "user_profiles" is missing. Please run the required migrations.', - ); + ) + .order("updated_at", { ascending: false }) + .limit(limit); + // resp may be { data, error } + if (!resp) throw new Error("Empty response from Supabase"); + const anyResp: any = resp as any; + const err = anyResp.error; + if (err) { + if (isTableMissing(err)) { + throw new Error( + 'Supabase table "user_profiles" is missing. Please run the required migrations.', + ); + } + throw new Error(err?.message || String(err)); } - throw error; + data = anyResp.data as any[]; + } catch (e: any) { + const msg = e?.message || JSON.stringify(e); + throw new Error(`Failed to list profiles: ${msg}`); } return ((data as any[]) || []).map((row) => {