mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-27 04:06:57 -05:00
Connect to Lovable Cloud
Improve CORS handling and error logging to fix moderation edge cases: - Add x-idempotency-key to allowed CORS headers and expose explicit POST methods - Extend CORS headers to include Access-Control-Allow-Methods - Update edge function tracing and client error handling to better detect and log CORS/network issues - Enhance error handling utilities to surface CORS-related failures and provide clearer user messages
This commit is contained in:
@@ -10,6 +10,7 @@ import { trackRequest } from './requestTracking';
|
||||
import { getErrorMessage } from './errorHandler';
|
||||
import { withRetry, isRetryableError, type RetryOptions } from './retryHelpers';
|
||||
import { breadcrumb } from './errorBreadcrumbs';
|
||||
import { logger } from './logger';
|
||||
|
||||
/**
|
||||
* Invoke a Supabase edge function with request tracking
|
||||
@@ -149,9 +150,31 @@ export async function invokeWithTracking<T = any>(
|
||||
}
|
||||
|
||||
const errorMessage = getErrorMessage(error);
|
||||
|
||||
// Detect CORS errors specifically
|
||||
const isCorsError = errorMessage.toLowerCase().includes('cors') ||
|
||||
errorMessage.toLowerCase().includes('cross-origin') ||
|
||||
errorMessage.toLowerCase().includes('failed to send') ||
|
||||
(error instanceof TypeError && errorMessage.toLowerCase().includes('failed to fetch'));
|
||||
|
||||
// Enhanced error logging
|
||||
logger.error('[EdgeFunctionTracking] Edge function invocation failed', {
|
||||
functionName,
|
||||
error: errorMessage,
|
||||
errorType: isCorsError ? 'CORS/Network' : (error as any)?.name || 'Unknown',
|
||||
attempts: attemptCount,
|
||||
isCorsError,
|
||||
debugHint: isCorsError ? 'Browser blocked request - verify CORS headers allow X-Idempotency-Key or check network connectivity' : undefined,
|
||||
status: (error as any)?.status,
|
||||
});
|
||||
|
||||
return {
|
||||
data: null,
|
||||
error: { message: errorMessage, status: (error as any)?.status },
|
||||
error: {
|
||||
message: errorMessage,
|
||||
status: (error as any)?.status,
|
||||
isCorsError,
|
||||
},
|
||||
requestId: 'unknown',
|
||||
duration: 0,
|
||||
attempts: attemptCount,
|
||||
|
||||
Reference in New Issue
Block a user