Fix critical error handling gaps in submission pipeline

Addressed real error handling issues identified during comprehensive
pipeline review:

1. **process-selective-approval edge function**
   - Added try-catch blocks around idempotency key updates (lines 216-262)
   - Prevents silent failures when updating submission status tracking
   - Updates are now non-blocking to ensure proper response delivery

2. **submissionItemsService.ts**
   - Added error logging before throwing in fetchSubmissionItems (line 75-81)
   - Added error handling for park location fetch failures (lines 99-107)
   - Location fetch errors are now logged as non-critical and don't block
     submission item retrieval

3. **notify-moderators-submission edge function**
   - Added error handling for notification log insert (lines 216-236)
   - Log failures are now non-blocking and properly logged
   - Ensures notification delivery isn't blocked by logging issues

4. **upload-image edge function**
   - Fixed CORS headers scope issue (line 127)
   - Moved corsHeaders definition outside try block
   - Prevents undefined reference in catch block error responses

All changes maintain backward compatibility and improve pipeline
resilience without altering functionality. Error handling is now
consistent with non-blocking patterns for auxiliary operations.
This commit is contained in:
Claude
2025-11-08 03:47:54 +00:00
parent a662b28cda
commit 571bf07b84
4 changed files with 70 additions and 34 deletions

View File

@@ -107,24 +107,25 @@ serve(withRateLimit(async (req) => {
const tracking = startRequest();
const requestOrigin = req.headers.get('origin');
const allowedOrigin = getAllowedOrigin(requestOrigin);
// Check if this is a CORS request with a disallowed origin
// Check if this is a CORS request with a disallowed origin
if (requestOrigin && !allowedOrigin) {
edgeLogger.warn('CORS request rejected', { action: 'cors_validation', origin: requestOrigin, requestId: tracking.requestId });
return new Response(
JSON.stringify({
JSON.stringify({
error: 'Origin not allowed',
message: 'The origin of this request is not allowed to access this resource'
}),
{
{
status: 403,
headers: { 'Content-Type': 'application/json' }
}
);
}
// Define CORS headers at function scope so they're available in catch block
const corsHeaders = getCorsHeaders(allowedOrigin);
// Handle CORS preflight requests
if (req.method === 'OPTIONS') {
return new Response(null, { headers: corsHeaders })