diff --git a/app/config/errors.php b/app/config/errors.php index b85841aa6..1986a6fc5 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -82,6 +82,11 @@ return [ 'description' => 'A user with the same email ID already exists in your project.', 'statusCode' => 409, ], + Exception::USER_INVALID_TOKEN => [ + 'name' => Exception::USER_INVALID_TOKEN, + 'description' => 'Invalid token.', + 'statusCode' => 401, + ], Exception::USER_BLOCKED => [ 'name' => Exception::USER_BLOCKED, 'description' => 'The current user has been blocked. Please contact the project administrator for more information.', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 50a28de35..441b2d75c 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -705,7 +705,7 @@ App::post('/v1/account/sessions/magic-url') $user = $dbForProject->updateDocument('users', $user->getId(), $user); if (false === $user) { - throw new Exception('Failed to save user to DB', 500, Exception::TYPE_USER_CREATION_FAILED); + throw new Exception('Failed to save user to DB', 500, Exception::USER_CREATION_FAILED); } if(empty($url)) { @@ -783,13 +783,13 @@ App::put('/v1/account/sessions/magic-url') $user = $dbForProject->getDocument('users', $userId); if ($user->isEmpty() || $user->getAttribute('deleted')) { - throw new Exception('User not found', 404, Exception::TYPE_USER_NOT_FOUND); + throw new Exception('User not found', 404, Exception::USER_NOT_FOUND); } $token = Auth::tokenVerify($user->getAttribute('tokens', []), Auth::TOKEN_TYPE_MAGIC_URL, $secret); if (!$token) { - throw new Exception('Invalid login token', 401, Exception::TYPE_INVALID_TOKEN); + throw new Exception('Invalid login token', 401, Exception::USER_INVALID_TOKEN); } $detector = new Detector($request->getUserAgent('UNKNOWN')); @@ -839,7 +839,7 @@ App::put('/v1/account/sessions/magic-url') $user = $dbForProject->updateDocument('users', $user->getId(), $user); if (false === $user) { - throw new Exception('Failed saving user to DB', 500, Exception::TYPE_USER_CREATION_FAILED); + throw new Exception('Failed saving user to DB', 500, Exception::USER_CREATION_FAILED); } $audits @@ -912,7 +912,7 @@ App::post('/v1/account/sessions/anonymous') $protocol = $request->getProtocol(); if ('console' === $project->getId()) { - throw new Exception('Failed to create anonymous user.', 401, Exception::TYPE_ANONYMOUS_CONSOLE_USER); + throw new Exception('Failed to create anonymous user.', 401); } if (!$user->isEmpty()) { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 2d39bdf28..ce2665fec 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -29,6 +29,7 @@ class Exception extends \Exception const USER_ALREADY_EXISTS = 'user_already_exists'; const USER_BLOCKED = 'user_blocked'; const USER_CREATION_FAILED = 'user_creation_failed'; + const USER_INVALID_TOKEN = 'user_invalid_token'; const USER_NOT_FOUND = 'user_not_found'; const USER_INVALID_CREDENTIALS = 'user_invalid_credentials'; const USER_EMAIL_ALREADY_EXISTS = 'user_email_already_exists';