From d0b1f5f52917ff54e6454a52ccbac5cbc86f67f9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 2 Dec 2025 02:09:29 +0000 Subject: [PATCH] Fix: Catch duplicate exception while creating file document --- app/controllers/api/storage.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 05156f1c45..1af157286c 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -681,7 +681,13 @@ App::post('/v1/storage/buckets/:bucketId/files') 'metadata' => $metadata, ]); - $file = $dbForProject->createDocument('bucket_' . $bucket->getSequence(), $doc); + try { + $file = $dbForProject->createDocument('bucket_' . $bucket->getSequence(), $doc); + } catch (DuplicateException) { + throw new Exception(Exception::STORAGE_FILE_ALREADY_EXISTS); + } catch (NotFoundException) { + throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); + } } else { $file = $file ->setAttribute('$permissions', $permissions) @@ -731,6 +737,8 @@ App::post('/v1/storage/buckets/:bucketId/files') try { $file = $dbForProject->createDocument('bucket_' . $bucket->getSequence(), $doc); + } catch (DuplicateException) { + throw new Exception(Exception::STORAGE_FILE_ALREADY_EXISTS); } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); }