mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 20:31:12 -05:00
Refactor: Implement full error logging
This commit is contained in:
@@ -9,8 +9,7 @@ import { Label } from '@/components/ui/label';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useProfile } from '@/hooks/useProfile';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { handleError, handleSuccess, AppError } from '@/lib/errorHandler';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { handleError, handleSuccess, handleNonCriticalError, AppError } from '@/lib/errorHandler';
|
||||
import { Download, Activity, BarChart3, AlertCircle, Clock } from 'lucide-react';
|
||||
import type {
|
||||
UserStatistics,
|
||||
|
||||
@@ -14,8 +14,7 @@ import { useAuth } from '@/hooks/useAuth';
|
||||
import { useProfile } from '@/hooks/useProfile';
|
||||
import { useUnitPreferences } from '@/hooks/useUnitPreferences';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { handleError, handleSuccess, AppError } from '@/lib/errorHandler';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { handleError, handleSuccess, handleNonCriticalError, AppError } from '@/lib/errorHandler';
|
||||
import { MapPin, Calendar, Accessibility, Ruler } from 'lucide-react';
|
||||
import type { LocationFormData, AccessibilityOptions, ParkOption } from '@/types/location';
|
||||
import {
|
||||
@@ -75,12 +74,6 @@ export function LocationTab() {
|
||||
.order('name');
|
||||
|
||||
if (error) {
|
||||
logger.error('Failed to fetch parks list', {
|
||||
userId: user.id,
|
||||
action: 'fetch_parks',
|
||||
error: error.message,
|
||||
errorCode: error.code
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -198,12 +191,6 @@ export function LocationTab() {
|
||||
.eq('user_id', user.id);
|
||||
|
||||
if (profileError) {
|
||||
logger.error('Failed to update profile', {
|
||||
userId: user.id,
|
||||
action: 'update_profile_location',
|
||||
error: profileError.message,
|
||||
errorCode: profileError.code
|
||||
});
|
||||
throw profileError;
|
||||
}
|
||||
|
||||
@@ -216,12 +203,6 @@ export function LocationTab() {
|
||||
.eq('user_id', user.id);
|
||||
|
||||
if (accessibilityError) {
|
||||
logger.error('Failed to update accessibility preferences', {
|
||||
userId: user.id,
|
||||
action: 'update_accessibility_preferences',
|
||||
error: accessibilityError.message,
|
||||
errorCode: accessibilityError.code
|
||||
});
|
||||
throw accessibilityError;
|
||||
}
|
||||
|
||||
@@ -246,22 +227,11 @@ export function LocationTab() {
|
||||
|
||||
await refreshProfile();
|
||||
|
||||
logger.info('Location and info settings updated', {
|
||||
userId: user.id,
|
||||
action: 'update_location_info'
|
||||
});
|
||||
|
||||
handleSuccess(
|
||||
'Settings saved',
|
||||
'Your location, personal information, accessibility, and unit preferences have been updated.'
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
logger.error('Error saving location settings', {
|
||||
userId: user.id,
|
||||
action: 'save_location_settings',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
|
||||
if (error instanceof z.ZodError) {
|
||||
handleError(
|
||||
new AppError(
|
||||
|
||||
@@ -9,8 +9,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { handleError, handleSuccess, handleInfo } from "@/lib/errorHandler";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { handleError, handleSuccess, handleInfo, handleNonCriticalError } from "@/lib/errorHandler";
|
||||
import { notificationService } from "@/lib/notificationService";
|
||||
import type {
|
||||
NotificationPreferences,
|
||||
@@ -53,18 +52,7 @@ export function NotificationsTab() {
|
||||
setWorkflowPreferences(preferences.workflowPreferences);
|
||||
setFrequencySettings(preferences.frequencySettings);
|
||||
}
|
||||
|
||||
logger.info('Notification preferences loaded', {
|
||||
action: 'load_notification_preferences',
|
||||
userId: user.id
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
logger.error('Failed to load notification preferences', {
|
||||
action: 'load_notification_preferences',
|
||||
userId: user.id,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
|
||||
handleError(error, {
|
||||
action: 'Load notification preferences',
|
||||
userId: user.id
|
||||
@@ -92,20 +80,8 @@ export function NotificationsTab() {
|
||||
if (Object.keys(initialPrefs).length > 0) {
|
||||
setWorkflowPreferences((prev) => ({ ...prev, ...initialPrefs }));
|
||||
}
|
||||
|
||||
logger.info('Notification templates loaded', {
|
||||
action: 'load_notification_templates',
|
||||
userId: user.id,
|
||||
count: templateData.length
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
logger.error('Failed to load notification templates', {
|
||||
action: 'load_notification_templates',
|
||||
userId: user.id,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
|
||||
handleError(error, {
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Load notification templates',
|
||||
userId: user.id
|
||||
});
|
||||
@@ -185,12 +161,6 @@ export function NotificationsTab() {
|
||||
);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
logger.error('Error requesting push permission', {
|
||||
action: 'request_push_permission',
|
||||
userId: user?.id,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
|
||||
handleError(error, {
|
||||
action: 'Enable push notifications',
|
||||
userId: user?.id
|
||||
|
||||
@@ -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