From 7160364902efdeca2277b1b73edf4090823fcf2d Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Feb 2022 19:57:15 +0400 Subject: [PATCH] feat: update error codes in the teams API --- app/config/errors.php | 5 +++++ app/controllers/api/teams.php | 4 ++-- 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 547356b2c..9fcb97c07 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -206,6 +206,11 @@ return [ 'description' => 'The membership ID does not belong to the team ID.', 'statusCode' => 404, ], + Exception::TEAM_INVITE_MISMATCH => [ + 'name' => Exception::TEAM_INVITE_MISMATCH, + 'description' => 'The invite does not belong to the current user.', + 'statusCode' => 401, + ], /** Membership */ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index c3fc90c05..9f428ad57 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -639,7 +639,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') } if ($userId != $membership->getAttribute('userId')) { - throw new Exception('Invite does not belong to current user ('.$user->getAttribute('email').')', 401); + throw new Exception('Invite does not belong to current user ('.$user->getAttribute('email').')', 401, Exception::TEAM_INVITE_MISMATCH); } if ($user->isEmpty()) { @@ -647,7 +647,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') } if ($membership->getAttribute('userId') !== $user->getId()) { - throw new Exception('Invite does not belong to current user ('.$user->getAttribute('email').')', 401); + throw new Exception('Invite does not belong to current user ('.$user->getAttribute('email').')', 401, Exception::TEAM_INVITE_MISMATCH); } $membership // Attach user to team diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 031fe9ec7..baa42c98d 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -59,6 +59,7 @@ class Exception extends \Exception const TEAM_INVITE_NOT_FOUND = 'team_invite_not_found'; const TEAM_INVALID_SECRET = 'team_invalid_secret'; const TEAM_MEMBERSHIP_MISMATCH = 'team_membership_mismatch'; + const TEAM_INVITE_MISMATCH = 'team_invite_mismatch'; /** Membership */ const MEMBERSHIP_NOT_FOUND = 'membership_not_found';