mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 08:51:16 -05:00
feat: Complete app-wide error coverage
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { handleError } from '@/lib/errorHandler';
|
||||
|
||||
// Profile schema (matches database JSONB structure)
|
||||
const ProfileSchema = z.object({
|
||||
@@ -101,8 +101,11 @@ export function validateModerationItems(data: unknown): {
|
||||
const result = ModerationItemArraySchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
logger.error('❌ Data validation failed', {
|
||||
errors: result.error.issues.slice(0, 5) // Log first 5 issues
|
||||
handleError(result.error, {
|
||||
action: 'Data validation failed',
|
||||
metadata: {
|
||||
errors: result.error.issues.slice(0, 5)
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { logger } from './logger';
|
||||
import { handleError, handleNonCriticalError } from './errorHandler';
|
||||
|
||||
export interface SubmissionMetadataInsert {
|
||||
submission_id: string;
|
||||
@@ -37,7 +37,10 @@ export async function writeSubmissionMetadata(
|
||||
.insert(entries);
|
||||
|
||||
if (error) {
|
||||
logger.error('Failed to write submission metadata', { error, submissionId });
|
||||
handleError(error, {
|
||||
action: 'Write submission metadata',
|
||||
metadata: { submissionId }
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +59,10 @@ export async function readSubmissionMetadata(
|
||||
.order('display_order');
|
||||
|
||||
if (error) {
|
||||
logger.error('Failed to read submission metadata', { error, submissionId });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Read submission metadata',
|
||||
metadata: { submissionId }
|
||||
});
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import type { ParkSubmissionData, RideSubmissionData, CompanySubmissionData, RideModelSubmissionData } from '@/types/submission-data';
|
||||
import { logger } from './logger';
|
||||
import { handleNonCriticalError } from './errorHandler';
|
||||
import {
|
||||
randomInt,
|
||||
randomFloat,
|
||||
@@ -352,12 +352,18 @@ export async function clearTestData(): Promise<{ deleted: number }> {
|
||||
.neq('id', '00000000-0000-0000-0000-000000000000'); // Delete all records
|
||||
|
||||
if (registryError) {
|
||||
logger.error('Error clearing test data registry', { error: registryError });
|
||||
handleNonCriticalError(registryError, {
|
||||
action: 'Clear test data registry',
|
||||
metadata: { operation: 'clearTestData' }
|
||||
});
|
||||
}
|
||||
|
||||
return { deleted: submissionCount };
|
||||
} catch (error: unknown) {
|
||||
logger.error('Error clearing test data', { error: error instanceof Error ? error.message : String(error) });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Clear test data',
|
||||
metadata: { operation: 'clearTestData' }
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import type { EntityType } from '@/types/versioning';
|
||||
import { createTableQuery } from './supabaseHelpers';
|
||||
import { logger } from './logger';
|
||||
import { handleNonCriticalError } from './errorHandler';
|
||||
|
||||
/**
|
||||
* Manually trigger cleanup of old versions for a specific entity type
|
||||
@@ -38,7 +38,10 @@ export async function cleanupVersions(
|
||||
});
|
||||
|
||||
if (error) {
|
||||
logger.error('Version cleanup failed', { error, entityType, keepCount });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Version cleanup',
|
||||
metadata: { entityType, keepCount }
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -98,7 +101,10 @@ export async function getVersionStats(
|
||||
const { data, error } = result;
|
||||
|
||||
if (error || !data) {
|
||||
logger.error('Failed to fetch version stats', { error, entityType, entityId });
|
||||
handleNonCriticalError(error || new Error('No data returned'), {
|
||||
action: 'Fetch version stats',
|
||||
metadata: { entityType, entityId }
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { logger } from './logger';
|
||||
import { handleNonCriticalError } from './errorHandler';
|
||||
|
||||
// Generate anonymous session hash (no PII)
|
||||
function getSessionHash(): string {
|
||||
@@ -41,6 +41,9 @@ export async function trackPageView(
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
// Fail silently - don't break the page if tracking fails
|
||||
logger.error('Failed to track page view', { entityType, entityId });
|
||||
handleNonCriticalError(error, {
|
||||
action: 'Track page view',
|
||||
metadata: { entityType, entityId }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user