mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 23:31:12 -05:00
Implement Phase 3C error logging
This commit is contained in:
@@ -2,8 +2,7 @@ import { useState, useEffect } from 'react';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { ComboboxOption } from '@/components/ui/combobox';
|
||||
import { toast } from 'sonner';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { getErrorMessage } from '@/lib/errorHandler';
|
||||
import { handleNonCriticalError } from '@/lib/errorHandler';
|
||||
|
||||
export function useCountries() {
|
||||
const [countries, setCountries] = useState<ComboboxOption[]>([]);
|
||||
@@ -31,8 +30,7 @@ export function useCountries() {
|
||||
}))
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to fetch countries', { error: errorMsg });
|
||||
handleNonCriticalError(error, { action: 'Fetch countries' });
|
||||
toast.error('Failed to load countries', {
|
||||
description: 'Please refresh the page and try again.',
|
||||
});
|
||||
@@ -80,8 +78,10 @@ export function useStatesProvinces(country?: string) {
|
||||
}))
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to fetch states/provinces', { country, error: errorMsg });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Fetch states/provinces',
|
||||
metadata: { country },
|
||||
});
|
||||
toast.error('Failed to load states/provinces', {
|
||||
description: 'Please refresh the page and try again.',
|
||||
});
|
||||
@@ -120,8 +120,7 @@ export function useManufacturers() {
|
||||
}))
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to fetch manufacturers', { error: errorMsg });
|
||||
handleNonCriticalError(error, { action: 'Fetch manufacturers' });
|
||||
toast.error('Failed to load manufacturers', {
|
||||
description: 'Please refresh the page and try again.',
|
||||
});
|
||||
@@ -165,8 +164,10 @@ export function useRideModels(manufacturerId?: string) {
|
||||
}))
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to fetch ride models', { manufacturerId, error: errorMsg });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Fetch ride models',
|
||||
metadata: { manufacturerId },
|
||||
});
|
||||
toast.error('Failed to load ride models', {
|
||||
description: 'Please refresh the page and try again.',
|
||||
});
|
||||
@@ -208,8 +209,7 @@ export function useCompanyHeadquarters() {
|
||||
}))
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to fetch headquarters', { error: errorMsg });
|
||||
handleNonCriticalError(error, { action: 'Fetch headquarters' });
|
||||
toast.error('Failed to load headquarters', {
|
||||
description: 'Please refresh the page and try again.',
|
||||
});
|
||||
@@ -248,8 +248,7 @@ export function useOperators() {
|
||||
}))
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to fetch operators', { error: errorMsg });
|
||||
handleNonCriticalError(error, { action: 'Fetch operators' });
|
||||
toast.error('Failed to load operators', {
|
||||
description: 'Please refresh the page and try again.',
|
||||
});
|
||||
@@ -288,8 +287,7 @@ export function usePropertyOwners() {
|
||||
}))
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to fetch property owners', { error: errorMsg });
|
||||
handleNonCriticalError(error, { action: 'Fetch property owners' });
|
||||
toast.error('Failed to load property owners', {
|
||||
description: 'Please refresh the page and try again.',
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ export function useBanCheck() {
|
||||
navigate('/');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Ban check error', { error, userId: user.id });
|
||||
// Silent - ban check failure is non-critical, user proceeds normally
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { toast } from 'sonner';
|
||||
import { getErrorMessage, handleNonCriticalError } from '@/lib/errorHandler';
|
||||
import { getErrorMessage, handleNonCriticalError, handleError } from '@/lib/errorHandler';
|
||||
import type { EntityType, EntityVersion } from '@/types/versioning';
|
||||
import { logger } from '@/lib/logger';
|
||||
|
||||
@@ -117,11 +117,13 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
setLoading(false);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to fetch versions', { entityType, entityId, error: errorMsg });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Fetch entity versions',
|
||||
metadata: { entityType, entityId },
|
||||
});
|
||||
|
||||
if (isMountedRef.current && currentRequestId === requestCounterRef.current) {
|
||||
toast.error(errorMsg);
|
||||
toast.error(getErrorMessage(error));
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
@@ -149,10 +151,12 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
|
||||
return data;
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to compare versions', { entityType, fromVersionId, toVersionId, error: errorMsg });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Compare entity versions',
|
||||
metadata: { entityType, fromVersionId, toVersionId },
|
||||
});
|
||||
if (isMountedRef.current) {
|
||||
toast.error(errorMsg);
|
||||
toast.error(getErrorMessage(error));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -187,11 +191,13 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
}
|
||||
return data;
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to rollback version', { entityType, entityId, targetVersionId, error: errorMsg });
|
||||
handleError(error, {
|
||||
action: 'Rollback entity version',
|
||||
metadata: { entityType, entityId, targetVersionId },
|
||||
});
|
||||
if (isMountedRef.current) {
|
||||
toast.error('Failed to restore version', {
|
||||
description: errorMsg
|
||||
description: getErrorMessage(error)
|
||||
});
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { useState, useEffect, useMemo, useCallback } from 'react';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { Park, Ride, Company } from '@/types/database';
|
||||
import { logger } from '@/lib/logger';
|
||||
import * as storage from '@/lib/localStorage';
|
||||
import { toast } from 'sonner';
|
||||
import { getErrorMessage } from '@/lib/errorHandler';
|
||||
import { handleNonCriticalError } from '@/lib/errorHandler';
|
||||
|
||||
export interface SearchResult {
|
||||
id: string;
|
||||
@@ -167,11 +166,9 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
|
||||
setResults(searchResults.slice(0, limit));
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Search failed', {
|
||||
query: searchQuery,
|
||||
types,
|
||||
error: errorMsg
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Search',
|
||||
metadata: { query: searchQuery, types },
|
||||
});
|
||||
|
||||
toast.error('Search failed', {
|
||||
@@ -180,7 +177,7 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
|
||||
setError('Failed to search. Please try again.');
|
||||
setResults([]);
|
||||
} finally {
|
||||
} finally{
|
||||
setLoading(false);
|
||||
}
|
||||
}, [types, limit, minQuery]);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useAuth } from './useAuth';
|
||||
import { useRequireMFA } from './useRequireMFA';
|
||||
import { getSessionAal } from '@/lib/authService';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { handleNonCriticalError } from '@/lib/errorHandler';
|
||||
|
||||
/**
|
||||
* Phase 3: Session Monitoring Hook
|
||||
@@ -56,10 +57,9 @@ export function useSessionMonitor() {
|
||||
}, 30000);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
logger.error('Session monitor check failed', {
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Session monitor check',
|
||||
userId: user.id,
|
||||
action: 'session_monitor',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
}
|
||||
}, 60000);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { queryKeys } from '@/lib/queryKeys';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { handleNonCriticalError } from '@/lib/errorHandler';
|
||||
|
||||
export type UserRole = 'admin' | 'moderator' | 'user' | 'superuser';
|
||||
|
||||
@@ -30,7 +30,10 @@ export function useUserRole() {
|
||||
.eq('user_id', user.id);
|
||||
|
||||
if (error) {
|
||||
logger.error('Error fetching user roles', { error, userId: user.id });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Fetch user roles',
|
||||
userId: user.id,
|
||||
});
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -51,7 +54,10 @@ export function useUserRole() {
|
||||
.rpc('get_user_management_permissions', { _user_id: user.id });
|
||||
|
||||
if (error) {
|
||||
logger.error('Error fetching user permissions', { error, userId: user.id });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Fetch user permissions',
|
||||
userId: user.id,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user