Fix: Handle RPC errors gracefully

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 19:07:38 +00:00
parent 16940419e5
commit ff2215f450
4 changed files with 100 additions and 27 deletions

View File

@@ -191,10 +191,19 @@ export const ReportsQueue = forwardRef<ReportsQueueRef>((props, ref) => {
const reporterIds = [...new Set((data || []).map(r => r.reporter_id))];
// Fetch reporter profiles with emails (for admins)
const { data: allProfiles } = await supabase
let profiles: Array<{ user_id: string; username: string; display_name?: string | null; avatar_url?: string | null }> | null = null;
const { data: allProfiles, error: rpcError } = await supabase
.rpc('get_users_with_emails');
const profiles = allProfiles?.filter(p => reporterIds.includes(p.user_id));
if (rpcError) {
const { data: basicProfiles } = await supabase
.from('profiles')
.select('user_id, username, display_name, avatar_url')
.in('user_id', reporterIds);
profiles = basicProfiles as typeof profiles;
} else {
profiles = allProfiles?.filter(p => reporterIds.includes(p.user_id)) || null;
}
const profileMap = new Map(profiles?.map(p => [p.user_id, p]) || []);
@@ -220,7 +229,16 @@ export const ReportsQueue = forwardRef<ReportsQueueRef>((props, ref) => {
profileIds.length > 0
? supabase
.rpc('get_users_with_emails')
.then(({ data }) => data?.filter(p => profileIds.includes(p.user_id)) || [])
.then(({ data, error }) => {
if (error) {
return supabase
.from('profiles')
.select('user_id, username, display_name')
.in('user_id', profileIds)
.then(({ data: basicProfiles }) => basicProfiles || []);
}
return data?.filter(p => profileIds.includes(p.user_id)) || [];
})
: Promise.resolve([]),
submissionIds.length > 0