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

@@ -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);