feat: update error codes in the accounts API
This commit is contained in:
parent
7f29a9e8c9
commit
d3efbc1ef5
|
@ -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.',
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in a new issue