From 4905792bb566be7ab77b2ac3102ffadb22edc685 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Feb 2022 18:40:22 +0400 Subject: [PATCH] feat: update error codes in the storage API --- app/config/errors.php | 7 ++++++- app/controllers/api/storage.php | 2 +- src/Appwrite/Extend/Exception.php | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index bfe1c2ec65..fc5d8ab871 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -241,7 +241,12 @@ return [ ], Exception::STORAGE_FAILED_TO_MOVE_FILE => [ 'name' => Exception::STORAGE_FAILED_TO_MOVE_FILE, - 'description' => 'Failed to copy the uploaded file.', + 'description' => 'Failed to move the uploaded file.', + 'statusCode' => 500, + ], + Exception::STORAGE_FAILED_TO_WRITE_FILE => [ + 'name' => Exception::STORAGE_FAILED_TO_WRITE_FILE, + 'description' => 'Failed to save the uploaded file.', 'statusCode' => 500, ], ]; \ No newline at end of file diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 63d9bf0ee9..b6e014eb71 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -141,7 +141,7 @@ App::post('/v1/storage/files') $data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag); if (!$device->write($path, $data, $mimeType)) { - throw new Exception('Failed to save file', 500); + throw new Exception('Failed to save file', 500, Exception::STORAGE_FAILED_TO_WRITE_FILE); } $sizeActual = $device->getFileSize($path); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 819115e789..2b585d4b57 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -68,6 +68,7 @@ class Exception extends \Exception const STORAGE_INVALID_FILE_SIZE = 'storage_invalid_file_size'; const STORAGE_INVALID_FILE = 'storage_invalid_file'; const STORAGE_FAILED_TO_MOVE_FILE = 'storage_failed_to_move_file'; + const STORAGE_FAILED_TO_WRITE_FILE = 'storage_failed_to_write_file'; /** Projects */ const PROJECT_NOT_FOUND = 'project_not_found';