mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-25 06:31:17 -05:00
Refactor: Implement full error logging
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { handleError, handleSuccess, AppError, getErrorMessage } from '@/lib/errorHandler';
|
||||
import { handleError, handleSuccess, handleNonCriticalError, AppError, getErrorMessage } from '@/lib/errorHandler';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { Loader2, Shield, CheckCircle2 } from 'lucide-react';
|
||||
@@ -82,9 +82,10 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
const hasVerifiedTotp = data?.totp?.some(factor => factor.status === 'verified') || false;
|
||||
setHasMFA(hasVerifiedTotp);
|
||||
} catch (error: unknown) {
|
||||
logger.error('Failed to check MFA status', {
|
||||
action: 'check_mfa_status',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Check MFA status',
|
||||
userId,
|
||||
metadata: { context: 'password_change_dialog' }
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -142,13 +143,6 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
setCaptchaToken('');
|
||||
setCaptchaKey(prev => prev + 1);
|
||||
|
||||
logger.error('Password authentication failed', {
|
||||
userId,
|
||||
action: 'password_change_auth',
|
||||
error: signInError.message,
|
||||
errorCode: signInError.code
|
||||
});
|
||||
|
||||
throw signInError;
|
||||
}
|
||||
|
||||
@@ -169,18 +163,6 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
await updatePasswordWithNonce(data.newPassword, generatedNonce);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const errorDetails = isErrorWithCode(error) ? {
|
||||
errorCode: error.code,
|
||||
errorStatus: error.status
|
||||
} : {};
|
||||
|
||||
logger.error('Password change failed', {
|
||||
userId,
|
||||
action: 'password_change',
|
||||
error: getErrorMessage(error),
|
||||
...errorDetails
|
||||
});
|
||||
|
||||
const errorMessage = getErrorMessage(error);
|
||||
const errorStatus = isErrorWithCode(error) ? error.status : undefined;
|
||||
|
||||
@@ -238,12 +220,6 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
});
|
||||
|
||||
if (challengeError) {
|
||||
logger.error('MFA challenge creation failed', {
|
||||
userId,
|
||||
action: 'password_change_mfa_challenge',
|
||||
error: challengeError.message,
|
||||
errorCode: challengeError.code
|
||||
});
|
||||
throw challengeError;
|
||||
}
|
||||
|
||||
@@ -255,24 +231,12 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
});
|
||||
|
||||
if (verifyError) {
|
||||
logger.error('MFA verification failed', {
|
||||
userId,
|
||||
action: 'password_change_mfa',
|
||||
error: verifyError.message,
|
||||
errorCode: verifyError.code
|
||||
});
|
||||
throw verifyError;
|
||||
}
|
||||
|
||||
// TOTP verified, now update password
|
||||
await updatePasswordWithNonce(newPassword, nonce);
|
||||
} catch (error: unknown) {
|
||||
logger.error('MFA verification failed', {
|
||||
userId,
|
||||
action: 'password_change_mfa',
|
||||
error: getErrorMessage(error)
|
||||
});
|
||||
|
||||
handleError(
|
||||
new AppError(
|
||||
getErrorMessage(error) || 'Invalid authentication code',
|
||||
@@ -325,10 +289,10 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
user.id
|
||||
);
|
||||
} catch (notifError) {
|
||||
logger.error('Failed to send password change notification', {
|
||||
handleNonCriticalError(notifError, {
|
||||
action: 'Send password change notification',
|
||||
userId: user!.id,
|
||||
action: 'password_change_notification',
|
||||
error: getErrorMessage(notifError)
|
||||
metadata: { context: 'post_password_change' }
|
||||
});
|
||||
// Don't fail the password update if notification fails
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user