Implement Phase 3C error logging

This commit is contained in:
gpt-engineer-app[bot]
2025-11-04 19:39:55 +00:00
parent 162d288cb0
commit a9334c7a3a
13 changed files with 179 additions and 210 deletions

View File

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