mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 14:51:13 -05:00
Fix error handling
This commit is contained in:
@@ -4,6 +4,7 @@ import { MFAChallenge } from './MFAChallenge';
|
|||||||
import { Shield, AlertCircle, Loader2 } from 'lucide-react';
|
import { Shield, AlertCircle, Loader2 } from 'lucide-react';
|
||||||
import { getEnrolledFactors } from '@/lib/authService';
|
import { getEnrolledFactors } from '@/lib/authService';
|
||||||
import { useAuth } from '@/hooks/useAuth';
|
import { useAuth } from '@/hooks/useAuth';
|
||||||
|
import { handleError } from '@/lib/errorHandler';
|
||||||
|
|
||||||
interface AutoMFAVerificationModalProps {
|
interface AutoMFAVerificationModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -46,7 +47,10 @@ export function AutoMFAVerificationModal({
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError('Failed to load MFA settings. Please try again.');
|
setError('Failed to load MFA settings. Please try again.');
|
||||||
console.error('Failed to fetch MFA factors:', err);
|
handleError(err, {
|
||||||
|
action: 'Fetch MFA Factors for Auto-Verification',
|
||||||
|
metadata: { context: 'AutoMFAVerificationModal' }
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { supabase } from "@/lib/supabaseClient";
|
import { supabase } from "@/lib/supabaseClient";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
import { getErrorMessage } from "@/lib/errorHandler";
|
import { handleError } from "@/lib/errorHandler";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp";
|
import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp";
|
||||||
@@ -45,10 +45,13 @@ export function MFAChallenge({ factorId, onSuccess, onCancel }: MFAChallengeProp
|
|||||||
onSuccess();
|
onSuccess();
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
toast({
|
handleError(error, {
|
||||||
variant: "destructive",
|
action: 'MFA Verification',
|
||||||
title: "Verification Failed",
|
metadata: {
|
||||||
description: getErrorMessage(error) || "Invalid code. Please try again.",
|
factorId,
|
||||||
|
codeLength: code.length,
|
||||||
|
context: 'MFAChallenge'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
setCode("");
|
setCode("");
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { AutoMFAVerificationModal } from './AutoMFAVerificationModal';
|
|||||||
import { MFAEnrollmentRequired } from './MFAEnrollmentRequired';
|
import { MFAEnrollmentRequired } from './MFAEnrollmentRequired';
|
||||||
import { useAuth } from '@/hooks/useAuth';
|
import { useAuth } from '@/hooks/useAuth';
|
||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
|
import { handleError } from '@/lib/errorHandler';
|
||||||
|
|
||||||
interface MFAGuardProps {
|
interface MFAGuardProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -24,13 +25,21 @@ export function MFAGuard({ children }: MFAGuardProps) {
|
|||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const handleVerificationSuccess = async () => {
|
const handleVerificationSuccess = async () => {
|
||||||
// Refresh the session to get updated AAL level
|
try {
|
||||||
await verifySession();
|
// Refresh the session to get updated AAL level
|
||||||
|
await verifySession();
|
||||||
toast({
|
|
||||||
title: 'Verification Successful',
|
toast({
|
||||||
description: 'You can now access this area.',
|
title: 'Verification Successful',
|
||||||
});
|
description: 'You can now access this area.',
|
||||||
|
});
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleError(error, {
|
||||||
|
action: 'MFA Session Verification',
|
||||||
|
metadata: { context: 'MFAGuard' }
|
||||||
|
});
|
||||||
|
// Still attempt to show content - session might be valid despite refresh error
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVerificationCancel = () => {
|
const handleVerificationCancel = () => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, useRef } from 'react';
|
|||||||
import { supabase } from '@/lib/supabaseClient';
|
import { supabase } from '@/lib/supabaseClient';
|
||||||
import { useAuth } from './useAuth';
|
import { useAuth } from './useAuth';
|
||||||
import { useToast } from './use-toast';
|
import { useToast } from './use-toast';
|
||||||
import { getErrorMessage, handleNonCriticalError } from '@/lib/errorHandler';
|
import { getErrorMessage, handleNonCriticalError, handleError } from '@/lib/errorHandler';
|
||||||
import { getSubmissionTypeLabel } from '@/lib/moderation/entities';
|
import { getSubmissionTypeLabel } from '@/lib/moderation/entities';
|
||||||
import { logger } from '@/lib/logger';
|
import { logger } from '@/lib/logger';
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
|
|||||||
// Start countdown timer for restored lock
|
// Start countdown timer for restored lock
|
||||||
startLockTimer(expiresAt);
|
startLockTimer(expiresAt);
|
||||||
|
|
||||||
console.log('Lock state restored from database', {
|
logger.info('Lock state restored from database', {
|
||||||
submissionId: data.id,
|
submissionId: data.id,
|
||||||
expiresAt: expiresAt.toISOString(),
|
expiresAt: expiresAt.toISOString(),
|
||||||
});
|
});
|
||||||
@@ -203,8 +203,8 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
|
|||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
// Log but don't show user toast (they haven't taken any action yet)
|
// Log but don't show user toast (they haven't taken any action yet)
|
||||||
console.debug('Failed to restore lock state', {
|
logger.debug('Failed to restore lock state', {
|
||||||
error: error instanceof Error ? error.message : String(error),
|
error: getErrorMessage(error),
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -608,10 +608,10 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
toast({
|
handleError(error, {
|
||||||
title: 'Failed to Release Lock',
|
action: 'Superuser Release Lock',
|
||||||
description: getErrorMessage(error),
|
userId: user.id,
|
||||||
variant: 'destructive',
|
metadata: { submissionId }
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -647,10 +647,10 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
|
|||||||
|
|
||||||
return count;
|
return count;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
toast({
|
handleError(error, {
|
||||||
title: 'Failed to Clear Locks',
|
action: 'Superuser Clear All Locks',
|
||||||
description: getErrorMessage(error),
|
userId: user.id,
|
||||||
variant: 'destructive',
|
metadata: { attemptedAction: 'bulk_release' }
|
||||||
});
|
});
|
||||||
return 0;
|
return 0;
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user