diff --git a/app/config/errors.php b/app/config/errors.php index 1986a6fc5..961231475 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -92,6 +92,16 @@ return [ 'description' => 'The current user has been blocked. Please contact the project administrator for more information.', 'statusCode' => 401, ], + Exception::USER_ANONYMOUS_CONSOLE_PROHIBITED => [ + 'name' => Exception::USER_ANONYMOUS_CONSOLE_PROHIBITED, + 'description' => 'Anonymous users cannot be created for console project.', + 'statusCode' => 401, + ], + Exception::USER_SESSION_ALREADY_EXISTS => [ + 'name' => Exception::USER_SESSION_ALREADY_EXISTS, + 'description' => 'Cannot create anonymous user when a session is active.', + 'statusCode' => 401, + ], Exception::USER_CREATION_FAILED => [ 'name' => Exception::USER_CREATION_FAILED, 'description' => 'There was an internal server error while creating the user.', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 441b2d75c..1e6ae7c59 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -912,11 +912,11 @@ App::post('/v1/account/sessions/anonymous') $protocol = $request->getProtocol(); if ('console' === $project->getId()) { - throw new Exception('Failed to create anonymous user.', 401); + throw new Exception('Failed to create anonymous user.', 401, Exception::USER_ANONYMOUS_CONSOLE_PROHIBITED); } if (!$user->isEmpty()) { - throw new Exception('Cannot create an anonymous user when logged in.', 401, Exception::TYPE_SESSION_ALREADY_EXISTS); + throw new Exception('Cannot create an anonymous user when logged in.', 401, Exception::USER_SESSION_ALREADY_EXISTS); } $limit = $project->getAttribute('auths', [])['limit'] ?? 0; diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index ce2665fec..76e44cc13 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -25,19 +25,21 @@ class Exception extends \Exception */ /** Users */ - const USER_COUNT_EXCEEDED = 'user_count_exceeded'; - 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'; - const USER_PASSWORD_MISMATCH = 'user_password_mismatch'; - const USER_AUTH_METHOD_UNSUPPORTED = 'user_auth_method_unsupported'; - const USER_PASSWORD_RESET_REQUIRED = 'user_password_reset_required'; - const USER_EMAIL_NOT_WHITELISTED = 'user_email_not_whitelisted'; - const USER_IP_NOT_WHITELISTED = 'user_ip_not_whitelisted'; + const USER_COUNT_EXCEEDED = 'user_count_exceeded'; + 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'; + const USER_PASSWORD_MISMATCH = 'user_password_mismatch'; + const USER_AUTH_METHOD_UNSUPPORTED = 'user_auth_method_unsupported'; + const USER_PASSWORD_RESET_REQUIRED = 'user_password_reset_required'; + const USER_EMAIL_NOT_WHITELISTED = 'user_email_not_whitelisted'; + const USER_IP_NOT_WHITELISTED = 'user_ip_not_whitelisted'; + const USER_SESSION_ALREADY_EXISTS = 'user_session_already_exists'; + const USER_ANONYMOUS_CONSOLE_PROHIBITED = 'user_anonymous_console_prohibited'; /** OAuth **/ const OAUTH_PROVIDER_DISABLED = 'oauth_provider_disabled';