Fix critical error handling and race condition issues

🔴 Critical fixes:
- Fix race condition: processImmediately now properly fails if job creation fails
- Fix silent job failures: job creation failures now throw errors instead of warnings
- Ensure atomic operations: either email + job succeed together, or both fail

⚠️ Improvements:
- Simplify error handling in processEmailJob to be more consistent
- Add proper validation for missing PayloadCMS jobs configuration
- Make error messages more descriptive and actionable
This commit is contained in:
2025-09-14 20:32:23 +02:00
parent b6ec55bc45
commit 27d504079a
2 changed files with 33 additions and 31 deletions

View File

@@ -64,13 +64,7 @@ export const processEmailJob = {
}
}
} catch (error) {
// Re-throw Error instances to preserve stack trace and error context
if (error instanceof Error) {
throw error
} else {
// Only wrap non-Error values
throw new Error(`Failed to process email ${emailId}: ${String(error)}`)
}
throw new Error(`Failed to process email ${emailId}: ${error instanceof Error ? error.message : String(error)}`)
}
}
}