feat: Implement comprehensive error handling

This commit is contained in:
gpt-engineer-app[bot]
2025-11-04 17:34:16 +00:00
parent 2a2f172c3b
commit 87589ee08f
3 changed files with 675 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import { useAuth } from './useAuth';
import { useToast } from './use-toast';
import { getErrorMessage } from '@/lib/errorHandler';
import { getSubmissionTypeLabel } from '@/lib/moderation/entities';
import { logger } from '@/lib/logger';
interface QueuedSubmission {
submission_id: string;
@@ -45,7 +46,11 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
try {
await supabase.rpc('release_expired_locks');
} catch (error: unknown) {
// Silent failure - lock release happens periodically
// Log expected periodic failure for debugging without user toast
logger.debug('Periodic lock release failed', {
operation: 'release_expired_locks',
error: getErrorMessage(error)
});
}
}, 120000); // 2 minutes
@@ -76,16 +81,20 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
{ pendingCount: 0, avgWaitHours: 0 }
);
setQueueStats({
pendingCount: totals.pendingCount,
assignedToMe: assignedCount || 0,
avgWaitHours: slaData.length > 0 ? totals.avgWaitHours / slaData.length : 0,
});
}
} catch (error: unknown) {
// Silent failure - stats are refreshed periodically
setQueueStats({
pendingCount: totals.pendingCount,
assignedToMe: assignedCount || 0,
avgWaitHours: slaData.length > 0 ? totals.avgWaitHours / slaData.length : 0,
});
}
}, [user]);
} catch (error: unknown) {
// Log stats fetch failure for debugging without user toast
logger.debug('Queue stats fetch failed', {
operation: 'fetchStats',
error: getErrorMessage(error)
});
}
}, [user]);
// Start countdown timer for lock expiry with improved memory leak prevention
const startLockTimer = useCallback((expiresAt: Date) => {
@@ -348,7 +357,13 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({ message: 'Failed to claim submission' }));
const errorData = await response.json().catch((parseError) => {
logger.warn('Failed to parse claim error response', {
error: getErrorMessage(parseError),
status: response.status
});
return { message: 'Failed to claim submission' };
});
throw new Error(errorData.message || 'Failed to claim submission');
}