mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 12:31:13 -05:00
feat: Implement comprehensive error logging
This commit is contained in:
@@ -100,6 +100,64 @@ export const handleInfo = (
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle non-critical errors (background failures) that should be logged
|
||||
* to the database WITHOUT showing user toasts
|
||||
* Use this for fire-and-forget operations where user shouldn't be interrupted
|
||||
*/
|
||||
export const handleNonCriticalError = (
|
||||
error: unknown,
|
||||
context: ErrorContext
|
||||
): string => {
|
||||
const errorId = crypto.randomUUID();
|
||||
const shortErrorId = errorId.slice(0, 8);
|
||||
|
||||
const errorMessage = error instanceof AppError
|
||||
? error.userMessage || error.message
|
||||
: error instanceof Error
|
||||
? error.message
|
||||
: 'An unexpected error occurred';
|
||||
|
||||
// Log to console/monitoring (same as handleError)
|
||||
logger.error('Non-critical error occurred', {
|
||||
...context,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
errorId,
|
||||
severity: 'low',
|
||||
});
|
||||
|
||||
// Log to database with breadcrumbs (non-blocking, fire-and-forget)
|
||||
try {
|
||||
const envContext = captureEnvironmentContext();
|
||||
const breadcrumbs = breadcrumbManager.getAll();
|
||||
|
||||
supabase.rpc('log_request_metadata', {
|
||||
p_request_id: errorId,
|
||||
p_user_id: context.userId || undefined,
|
||||
p_endpoint: context.action,
|
||||
p_method: 'NON_CRITICAL_ERROR',
|
||||
p_status_code: 500,
|
||||
p_error_type: error instanceof Error ? error.name : 'UnknownError',
|
||||
p_error_message: errorMessage,
|
||||
p_error_stack: error instanceof Error ? error.stack : undefined,
|
||||
p_user_agent: navigator.userAgent,
|
||||
p_breadcrumbs: JSON.stringify(breadcrumbs),
|
||||
p_timezone: envContext.timezone,
|
||||
p_referrer: document.referrer || undefined,
|
||||
}).then(({ error: dbError }) => {
|
||||
if (dbError) {
|
||||
logger.error('Failed to log non-critical error to database', { dbError });
|
||||
}
|
||||
});
|
||||
} catch (logError) {
|
||||
logger.error('Failed to capture non-critical error context', { logError });
|
||||
}
|
||||
|
||||
// NO TOAST - This is the key difference from handleError()
|
||||
return errorId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Type-safe error message extraction utility
|
||||
* Use this instead of `error: any` in catch blocks
|
||||
|
||||
Reference in New Issue
Block a user