From 6d343abcb1e4ff7c133fd59908847f64df02a5c4 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 7 Feb 2022 01:00:06 +0400 Subject: [PATCH] feat: use general server errors in teams API --- app/config/errors.php | 10 ---------- app/controllers/api/teams.php | 6 +++--- src/Appwrite/Extend/Exception.php | 2 -- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 05265dd20..403ff9b6d 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -211,11 +211,6 @@ return [ 'description' => 'Team with the requested ID could not be found.', 'code' => 404, ], - Exception::TEAM_DELETION_FAILED => [ - 'name' => Exception::TEAM_DELETION_FAILED, - 'description' => 'Failed to delete team from the database.', - 'code' => 500, - ], Exception::TEAM_INVITE_ALREADY_EXISTS => [ 'name' => Exception::TEAM_INVITE_ALREADY_EXISTS, 'description' => 'The current user already has an invitation to this team.', @@ -249,11 +244,6 @@ return [ 'description' => 'Membership with the requested ID could not be found.', 'code' => 404, ], - Exception::MEMBERSHIP_DELETION_FAILED => [ - 'name' => Exception::MEMBERSHIP_DELETION_FAILED, - 'description' => 'Failed to delete membership from the database.', - 'code' => 500, - ], /** Avatars */ Exception::AVATAR_SET_NOT_FOUND => [ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 9f428ad57..908a8a195 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -232,12 +232,12 @@ App::delete('/v1/teams/:teamId') // TODO delete all members individually from the user object foreach ($memberships as $membership) { if (!$dbForProject->deleteDocument('memberships', $membership->getId())) { - throw new Exception('Failed to remove membership for team from DB', 500, Exception::MEMBERSHIP_DELETION_FAILED); + throw new Exception('Failed to remove membership for team from DB', 500, Exception::GENERAL_SERVER_ERROR); } } if (!$dbForProject->deleteDocument('teams', $teamId)) { - throw new Exception('Failed to remove team from DB', 500, Exception::TEAM_DELETION_FAILED); + throw new Exception('Failed to remove team from DB', 500, Exception::GENERAL_SERVER_ERROR); } $deletes @@ -767,7 +767,7 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId') } catch (AuthorizationException $exception) { throw new Exception('Unauthorized permissions', 401, Exception::USER_UNAUTHORIZED); } catch (\Exception $exception) { - throw new Exception('Failed to remove membership from DB', 500, Exception::MEMBERSHIP_DELETION_FAILED); + throw new Exception('Failed to remove membership from DB', 500, Exception::GENERAL_SERVER_ERROR); } $memberships = $user->getAttribute('memberships', []); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 8f0b10ca1..0b85b12ed 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -51,7 +51,6 @@ class Exception extends \Exception /** Teams */ const TEAM_NOT_FOUND = 'team_not_found'; - const TEAM_DELETION_FAILED = 'team_deletion_failed'; const TEAM_INVITE_ALREADY_EXISTS = 'team_invite_already_exists'; const TEAM_INVITE_NOT_FOUND = 'team_invite_not_found'; const TEAM_INVALID_SECRET = 'team_invalid_secret'; @@ -60,7 +59,6 @@ class Exception extends \Exception /** Membership */ const MEMBERSHIP_NOT_FOUND = 'membership_not_found'; - const MEMBERSHIP_DELETION_FAILED = 'membership_deletion_failed'; /** Avatars */ const AVATAR_SET_NOT_FOUND = 'avatar_set_not_found';