Normalize errors in listProfiles

cgen-7c37ffdfc7a6413db03baa09beafcf2d
This commit is contained in:
Builder.io 2025-10-14 03:29:22 +00:00
parent 9d9c37d59b
commit 22f63a10b4

View file

@ -362,26 +362,36 @@ export const aethexUserService = {
async listProfiles(limit = 50): Promise<AethexUserProfile[]> { async listProfiles(limit = 50): Promise<AethexUserProfile[]> {
ensureSupabase(); ensureSupabase();
const { data, error } = await supabase let data: any[] | null = null;
.from("user_profiles") try {
.select( const resp = await supabase
` .from("user_profiles")
.select(
`
*, *,
user_achievements ( user_achievements (
achievements ( xp_reward ) achievements ( xp_reward )
) )
`, `,
) )
.order("updated_at", { ascending: false }) .order("updated_at", { ascending: false })
.limit(limit); .limit(limit);
// resp may be { data, error }
if (error) { if (!resp) throw new Error("Empty response from Supabase");
if (isTableMissing(error)) { const anyResp: any = resp as any;
throw new Error( const err = anyResp.error;
'Supabase table "user_profiles" is missing. Please run the required migrations.', 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) => { return ((data as any[]) || []).map((row) => {