diff --git a/app/config/errors.php b/app/config/errors.php index 0031130ed..bfe1c2ec6 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -239,4 +239,9 @@ return [ 'description' => 'The uploaded file is invalid. Please check the file and try again.', 'statusCode' => 403, ], + Exception::STORAGE_FAILED_TO_MOVE_FILE => [ + 'name' => Exception::STORAGE_FAILED_TO_MOVE_FILE, + 'description' => 'Failed to copy 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 cafad0787..63d9bf0ee 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -116,7 +116,7 @@ App::post('/v1/storage/files') $path = $device->getPath(\uniqid().'.'.\pathinfo($file['name'], PATHINFO_EXTENSION)); if (!$device->upload($file['tmp_name'], $path)) { // TODO deprecate 'upload' and replace with 'move' - throw new Exception('Failed moving file', 500); + throw new Exception('Failed moving file', 500, Exception::STORAGE_FAILED_TO_MOVE_FILE); } $mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption @@ -127,7 +127,7 @@ App::post('/v1/storage/files') if (!$antivirus->fileScan($path)) { $device->delete($path); - throw new Exception('Invalid file', 403); + throw new Exception('Invalid file', 403, Exception::STORAGE_INVALID_FILE); } } diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 4fa15eabd..819115e78 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -67,6 +67,7 @@ class Exception extends \Exception const STORAGE_INVALID_WRITE_PERMISSIONS = 'storage_invalid_write_permissions'; 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'; /** Projects */ const PROJECT_NOT_FOUND = 'project_not_found';