mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 13:11:12 -05:00
Fix: Handle RPC errors gracefully
This commit is contained in:
@@ -18,7 +18,7 @@ import {
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { handleError } from '@/lib/errorHandler';
|
||||
import { handleError, getErrorMessage } from '@/lib/errorHandler';
|
||||
import { logger } from '@/lib/logger';
|
||||
|
||||
interface Moderator {
|
||||
@@ -69,12 +69,22 @@ export function ReassignDialog({
|
||||
|
||||
const userIds = roles.map((r) => r.user_id);
|
||||
|
||||
const { data: allProfiles, error: profilesError } = await supabase
|
||||
let profiles: Array<{ user_id: string; username: string; display_name?: string | null }> | null = null;
|
||||
const { data: allProfiles, error: rpcError } = await supabase
|
||||
.rpc('get_users_with_emails');
|
||||
|
||||
const profiles = allProfiles?.filter(p => userIds.includes(p.user_id));
|
||||
if (rpcError) {
|
||||
logger.warn('Failed to fetch users with emails, using basic profiles', { error: getErrorMessage(rpcError) });
|
||||
const { data: basicProfiles } = await supabase
|
||||
.from('profiles')
|
||||
.select('user_id, username, display_name')
|
||||
.in('user_id', userIds);
|
||||
profiles = basicProfiles as typeof profiles;
|
||||
} else {
|
||||
profiles = allProfiles?.filter(p => userIds.includes(p.user_id)) || null;
|
||||
}
|
||||
|
||||
if (profilesError) throw profilesError;
|
||||
|
||||
|
||||
const moderatorsList = roles.map((role) => {
|
||||
const profile = profiles?.find((p) => p.user_id === role.user_id);
|
||||
|
||||
Reference in New Issue
Block a user