mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-29 19:07:07 -05:00
Implement Phase 3C error logging
This commit is contained in:
@@ -2,7 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
|
||||
import { invokeWithTracking } from '@/lib/edgeFunctionTracking';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { handleNonCriticalError } from '@/lib/errorHandler';
|
||||
import { UnitPreferences, getMeasurementSystemFromCountry } from '@/lib/units';
|
||||
import type { Json } from '@/integrations/supabase/types';
|
||||
import * as storage from '@/lib/localStorage';
|
||||
@@ -42,11 +42,9 @@ export function useUnitPreferences() {
|
||||
.maybeSingle();
|
||||
|
||||
if (error && error.code !== 'PGRST116') {
|
||||
logger.error('Failed to fetch unit preferences', {
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Fetch unit preferences',
|
||||
userId: user.id,
|
||||
action: 'fetch_unit_preferences',
|
||||
error: error.message,
|
||||
errorCode: error.code
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -71,10 +69,9 @@ export function useUnitPreferences() {
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
logger.error('Error loading unit preferences', {
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Load unit preferences',
|
||||
userId: user?.id,
|
||||
action: 'load_unit_preferences',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
await autoDetectPreferences();
|
||||
} finally {
|
||||
@@ -106,10 +103,9 @@ export function useUnitPreferences() {
|
||||
});
|
||||
|
||||
if (error) {
|
||||
logger.error('Error saving auto-detected preferences', {
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Save auto-detected preferences',
|
||||
userId: user.id,
|
||||
action: 'save_auto_detected_preferences',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -119,10 +115,9 @@ export function useUnitPreferences() {
|
||||
return newPreferences;
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
logger.error('Error auto-detecting location', {
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Auto-detect location',
|
||||
userId: user?.id,
|
||||
action: 'auto_detect_location',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -144,19 +139,13 @@ export function useUnitPreferences() {
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
.eq('user_id', user.id);
|
||||
|
||||
logger.info('Unit preferences updated', {
|
||||
userId: user.id,
|
||||
action: 'update_unit_preferences'
|
||||
});
|
||||
} else {
|
||||
storage.setJSON('unit_preferences', updated);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
logger.error('Error saving unit preferences', {
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Save unit preferences',
|
||||
userId: user?.id,
|
||||
action: 'save_unit_preferences',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
setPreferences(preferences);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user