mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:31:11 -05:00
Fix: Improve validation error handling
This commit is contained in:
@@ -837,10 +837,9 @@ serve(withRateLimit(async (req) => {
|
||||
|
||||
// Process items in order
|
||||
for (const item of sortedItems) {
|
||||
try {
|
||||
edgeLogger.info('Processing item', { action: 'approval_process_item', itemId: item.id, itemType: item.item_type });
|
||||
|
||||
// Extract data from relational tables based on item_type
|
||||
// Extract data from relational tables based on item_type (OUTSIDE try-catch)
|
||||
let itemData: any;
|
||||
switch (item.item_type) {
|
||||
case 'park':
|
||||
@@ -900,7 +899,7 @@ serve(withRateLimit(async (req) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Validate entity data with strict validation, passing original_data for edits
|
||||
// Validate entity data BEFORE entering try-catch (so 400 returns immediately)
|
||||
const validation = validateEntityDataStrict(item.item_type, itemData, item.original_data);
|
||||
|
||||
if (validation.blockingErrors.length > 0) {
|
||||
@@ -911,7 +910,7 @@ serve(withRateLimit(async (req) => {
|
||||
requestId: tracking.requestId
|
||||
});
|
||||
|
||||
// Fail the entire batch if ANY item has blocking errors
|
||||
// Return 400 immediately - NOT caught by try-catch below
|
||||
return new Response(JSON.stringify({
|
||||
success: false,
|
||||
message: 'Validation failed: Items have blocking errors that must be fixed',
|
||||
@@ -938,6 +937,8 @@ serve(withRateLimit(async (req) => {
|
||||
// Continue processing - warnings don't block approval
|
||||
}
|
||||
|
||||
// Now enter try-catch ONLY for database operations
|
||||
try {
|
||||
// Set user context for versioning trigger
|
||||
// This allows create_relational_version() trigger to capture the submitter
|
||||
const { error: setUserIdError } = await supabase.rpc('set_config_value', {
|
||||
|
||||
Reference in New Issue
Block a user