mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 15:51:12 -05:00
Improve error handling and display for searches and uploads
Enhance user feedback by displaying search errors, refine photo submission fetching, add rate limiting cleanup logic, improve image upload cleanup, and strengthen moderator permission checks. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 2741d09b-80fb-4f0a-bfd6-ababb2ac4bfc Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -106,16 +106,26 @@ export async function uploadPendingImages(images: UploadedImage[]): Promise<Uplo
|
||||
if (newlyUploadedImageIds.length > 0) {
|
||||
console.error(`imageUploadHelper.uploadPendingImages: Some uploads failed. Cleaning up ${newlyUploadedImageIds.length} newly uploaded images...`);
|
||||
|
||||
// Attempt cleanup in parallel but don't throw if it fails
|
||||
await Promise.allSettled(
|
||||
// Attempt cleanup in parallel with detailed error tracking
|
||||
const cleanupResults = await Promise.allSettled(
|
||||
newlyUploadedImageIds.map(imageId =>
|
||||
supabase.functions.invoke('upload-image', {
|
||||
body: { action: 'delete', imageId }
|
||||
}).catch(cleanupError => {
|
||||
console.error(`imageUploadHelper.uploadPendingImages: Failed to cleanup image ${imageId}:`, cleanupError);
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// Track cleanup failures for better debugging
|
||||
const cleanupFailures = cleanupResults.filter(r => r.status === 'rejected');
|
||||
if (cleanupFailures.length > 0) {
|
||||
console.error(
|
||||
`imageUploadHelper.uploadPendingImages: Failed to cleanup ${cleanupFailures.length} of ${newlyUploadedImageIds.length} images.`,
|
||||
'These images may remain orphaned in Cloudflare:',
|
||||
newlyUploadedImageIds.filter((_, i) => cleanupResults[i].status === 'rejected')
|
||||
);
|
||||
} else {
|
||||
console.log(`imageUploadHelper.uploadPendingImages: Successfully cleaned up ${newlyUploadedImageIds.length} images.`);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Failed to upload ${errors.length} of ${images.length} images: ${errors.join('; ')}`);
|
||||
|
||||
Reference in New Issue
Block a user