feat: update error codes in the teams API
This commit is contained in:
parent
5fc751a9dd
commit
c3369dec50
|
@ -186,8 +186,8 @@ return [
|
|||
'description' => 'Failed to delete team from the database.',
|
||||
'statusCode' => 500,
|
||||
],
|
||||
Exception::TEAM_INVITATION_ALREADY_EXISTS => [
|
||||
'name' => Exception::TEAM_INVITATION_ALREADY_EXISTS,
|
||||
Exception::TEAM_INVITE_ALREADY_EXISTS => [
|
||||
'name' => Exception::TEAM_INVITE_ALREADY_EXISTS,
|
||||
'description' => 'The current user already has an invitation to this team.',
|
||||
'statusCode' => 409,
|
||||
],
|
||||
|
@ -196,6 +196,16 @@ return [
|
|||
'description' => 'The requested invitation could not be found.',
|
||||
'statusCode' => 409,
|
||||
],
|
||||
Exception::TEAM_INVALID_SECRET => [
|
||||
'name' => Exception::TEAM_INVALID_SECRET,
|
||||
'description' => 'The team invitation secret is invalid.',
|
||||
'statusCode' => 401,
|
||||
],
|
||||
Exception::TEAM_MEMBERSHIP_MISMATCH => [
|
||||
'name' => Exception::TEAM_MEMBERSHIP_MISMATCH,
|
||||
'description' => 'The membership ID does not belong to the team ID.',
|
||||
'statusCode' => 404,
|
||||
],
|
||||
|
||||
|
||||
/** Membership */
|
||||
|
|
|
@ -370,7 +370,7 @@ App::post('/v1/teams/:teamId/memberships')
|
|||
try {
|
||||
$membership = Authorization::skip(fn() => $dbForProject->createDocument('memberships', $membership));
|
||||
} catch (Duplicate $th) {
|
||||
throw new Exception('User has already been invited or is already a member of this team', 409, Exception::TEAM_INVITATION_ALREADY_EXISTS);
|
||||
throw new Exception('User has already been invited or is already a member of this team', 409, Exception::TEAM_INVITE_ALREADY_EXISTS);
|
||||
}
|
||||
$team->setAttribute('sum', $team->getAttribute('sum', 0) + 1);
|
||||
$team = Authorization::skip(fn() => $dbForProject->updateDocument('teams', $team->getId(), $team));
|
||||
|
@ -383,7 +383,7 @@ App::post('/v1/teams/:teamId/memberships')
|
|||
try {
|
||||
$membership = $dbForProject->createDocument('memberships', $membership);
|
||||
} catch (Duplicate $th) {
|
||||
throw new Exception('User has already been invited or is already a member of this team', 409, Exception::TEAM_INVITATION_ALREADY_EXISTS);
|
||||
throw new Exception('User has already been invited or is already a member of this team', 409, Exception::TEAM_INVITE_ALREADY_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -625,7 +625,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status')
|
|||
}
|
||||
|
||||
if ($membership->getAttribute('teamId') !== $teamId) {
|
||||
throw new Exception('Team IDs don\'t match', 404);
|
||||
throw new Exception('Team IDs don\'t match', 404, Exception::TEAM_MEMBERSHIP_MISMATCH);
|
||||
}
|
||||
|
||||
$team = Authorization::skip(fn() => $dbForProject->getDocument('teams', $teamId));
|
||||
|
@ -635,7 +635,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status')
|
|||
}
|
||||
|
||||
if (Auth::hash($secret) !== $membership->getAttribute('secret')) {
|
||||
throw new Exception('Secret key not valid', 401);
|
||||
throw new Exception('Secret key not valid', 401, Exception::TEAM_INVALID_SECRET);
|
||||
}
|
||||
|
||||
if ($userId != $membership->getAttribute('userId')) {
|
||||
|
@ -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);
|
||||
throw new Exception('Failed to remove membership from DB', 500, Exception::MEMBERSHIP_DELETION_FAILED);
|
||||
}
|
||||
|
||||
$memberships = $user->getAttribute('memberships', []);
|
||||
|
|
|
@ -55,8 +55,10 @@ class Exception extends \Exception
|
|||
/** Teams */
|
||||
const TEAM_NOT_FOUND = 'team_not_found';
|
||||
const TEAM_DELETION_FAILED = 'team_deletion_failed';
|
||||
const TEAM_INVITATION_ALREADY_EXISTS = 'team_invitation_already_exists';
|
||||
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';
|
||||
const TEAM_MEMBERSHIP_MISMATCH = 'team_membership_mismatch';
|
||||
|
||||
/** Membership */
|
||||
const MEMBERSHIP_NOT_FOUND = 'membership_not_found';
|
||||
|
|
Loading…
Reference in a new issue