From 1613b3f79ec8cff84ce5f78e24bba2eefdfdc3aa Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 7 Feb 2022 00:53:26 +0400 Subject: [PATCH] feat: use general server errors in functions API --- app/config/errors.php | 15 --------------- app/controllers/api/functions.php | 6 +++--- src/Appwrite/Extend/Exception.php | 3 --- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 77083d687..2112f80b6 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -349,11 +349,6 @@ 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 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.', @@ -366,11 +361,6 @@ return [ 'description' => 'The requested function could not be found.', 'statusCode' => 404, ], - Exception::FUNCTION_DELETION_FAILED => [ - 'name' => Exception::FUNCTION_DELETION_FAILED, - 'description' => 'Failed to delete the function from the database.', - 'statusCode' => 500, - ], /** Deployments */ Exception::DEPLOYMENT_NOT_FOUND => [ @@ -378,11 +368,6 @@ return [ 'description' => 'The requested deployment could not be found.', 'statusCode' => 404, ], - Exception::DEPLOYMENT_DELETION_FAILED => [ - 'name' => Exception::DEPLOYMENT_DELETION_FAILED, - 'description' => 'Failed to delete the deployment from the database.', - 'statusCode' => 500, - ], /** Executions */ Exception::EXECUTION_NOT_FOUND => [ diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index ab0a1f5ba..d592ae267 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -420,7 +420,7 @@ App::delete('/v1/functions/:functionId') } if (!$dbForProject->deleteDocument('functions', $function->getId())) { - throw new Exception('Failed to remove function from DB', 500, Exception::FUNCTION_DELETION_FAILED); + throw new Exception('Failed to remove function from DB', 500, Exception::GENERAL_SERVER_ERROR); } $deletes @@ -496,7 +496,7 @@ App::post('/v1/functions/:functionId/tags') $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, Exception::STORAGE_FAILED_TO_MOVE_FILE); + throw new Exception('Failed moving file', 500, Exception::GENERAL_SERVER_ERROR); } $tagId = $dbForProject->getId(); @@ -654,7 +654,7 @@ App::delete('/v1/functions/:functionId/tags/:tagId') if ($device->delete($tag->getAttribute('path', ''))) { if (!$dbForProject->deleteDocument('tags', $tag->getId())) { - throw new Exception('Failed to remove tag from DB', 500, Exception::DEPLOYMENT_DELETION_FAILED); + throw new Exception('Failed to remove tag from DB', 500, Exception::GENERAL_SERVER_ERROR); } } diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index d4c67d50b..57d35b40c 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -78,16 +78,13 @@ class Exception extends \Exception const STORAGE_FILE_TYPE_UNSUPPORTED = 'storage_file_type_unsupported'; 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'; /** Functions */ const FUNCTION_NOT_FOUND = 'function_not_found'; - const FUNCTION_DELETION_FAILED = 'function_deletion_failed'; /** Deployments */ const DEPLOYMENT_NOT_FOUND = 'deployment_not_found'; - const DEPLOYMENT_DELETION_FAILED = 'deployment_deletion_failed'; /** Execution */ const EXECUTION_NOT_FOUND = 'execution_not_found';