mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 12:31:26 -05:00
Fix: Handle RPC errors gracefully
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user