mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 13:31:12 -05:00
Fix: Improve validation error handling
This commit is contained in:
@@ -837,10 +837,9 @@ serve(withRateLimit(async (req) => {
|
|||||||
|
|
||||||
// Process items in order
|
// Process items in order
|
||||||
for (const item of sortedItems) {
|
for (const item of sortedItems) {
|
||||||
try {
|
|
||||||
edgeLogger.info('Processing item', { action: 'approval_process_item', itemId: item.id, itemType: item.item_type });
|
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;
|
let itemData: any;
|
||||||
switch (item.item_type) {
|
switch (item.item_type) {
|
||||||
case 'park':
|
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);
|
const validation = validateEntityDataStrict(item.item_type, itemData, item.original_data);
|
||||||
|
|
||||||
if (validation.blockingErrors.length > 0) {
|
if (validation.blockingErrors.length > 0) {
|
||||||
@@ -911,7 +910,7 @@ serve(withRateLimit(async (req) => {
|
|||||||
requestId: tracking.requestId
|
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({
|
return new Response(JSON.stringify({
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Validation failed: Items have blocking errors that must be fixed',
|
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
|
// Continue processing - warnings don't block approval
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now enter try-catch ONLY for database operations
|
||||||
|
try {
|
||||||
// Set user context for versioning trigger
|
// Set user context for versioning trigger
|
||||||
// This allows create_relational_version() trigger to capture the submitter
|
// This allows create_relational_version() trigger to capture the submitter
|
||||||
const { error: setUserIdError } = await supabase.rpc('set_config_value', {
|
const { error: setUserIdError } = await supabase.rpc('set_config_value', {
|
||||||
|
|||||||
Reference in New Issue
Block a user