1
0
Fork 0
mirror of synced 2024-06-17 10:14:50 +12:00

feat: use general server errors in accounts API

This commit is contained in:
Christy Jacob 2022-02-07 00:36:15 +04:00
parent adf103730b
commit 49bfb25df6
3 changed files with 7 additions and 22 deletions

View file

@ -178,11 +178,6 @@ return [
'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.',
'statusCode' => 500,
],
Exception::USER_NOT_FOUND => [
'name' => Exception::USER_NOT_FOUND,
'description' => 'User with the requested ID could not be found.',
@ -225,11 +220,6 @@ return [
'description' => 'The chosen OAuth provider is unsupported.',
'statusCode' => 501,
],
Exception::OAUTH_INVALID_LOGIN_STATE_PARAMS => [
'name' => Exception::OAUTH_INVALID_LOGIN_STATE_PARAMS,
'description' => 'Failed to parse the login state params from the OAuth provider.',
'statusCode' => 500,
],
Exception::OAUTH_INVALID_SUCCESS_URL => [
'name' => Exception::OAUTH_INVALID_SUCCESS_URL,
'description' => 'Invalid URL received for OAuth success redirect.',
@ -240,11 +230,6 @@ return [
'description' => 'Invalid URL received for OAuth failure redirect.',
'statusCode' => 400,
],
Exception::OAUTH_ACCESS_TOKEN_FAILED => [
'name' => Exception::OAUTH_ACCESS_TOKEN_FAILED,
'description' => 'Failed to obtain access token from the OAuth provider.',
'statusCode' => 500,
],
Exception::OAUTH_MISSING_USER_ID => [
'name' => Exception::OAUTH_MISSING_USER_ID,
'description' => 'Failed to obtain user id from the OAuth provider.',

View file

@ -415,7 +415,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
try {
$state = \array_merge($defaultState, $oauth2->parseState($state));
} catch (\Exception$exception) {
throw new Exception('Failed to parse login state params as passed from OAuth2 provider', 500, Exception::OAUTH_INVALID_LOGIN_STATE_PARAMS);
throw new Exception('Failed to parse login state params as passed from OAuth2 provider', 500, Exception::GENERAL_SERVER_ERROR);
}
} else {
$state = $defaultState;
@ -437,7 +437,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
$response->redirect($state['failure'], 301, 0);
}
throw new Exception('Failed to obtain access token', 500, Exception::OAUTH_ACCESS_TOKEN_FAILED);
throw new Exception('Failed to obtain access token', 500, Exception::GENERAL_SERVER_ERROR);
}
$oauth2ID = $oauth2->getUserID($accessToken);
@ -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::USER_CREATION_FAILED);
throw new Exception('Failed to save user to DB', 500, Exception::GENERAL_SERVER_ERROR);
}
if(empty($url)) {
@ -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::USER_CREATION_FAILED);
throw new Exception('Failed saving user to DB', 500, Exception::GENERAL_SERVER_ERROR);
}
$audits

View file

@ -28,7 +28,6 @@ class Exception extends \Exception
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';
@ -46,10 +45,8 @@ class Exception extends \Exception
/** OAuth **/
const OAUTH_PROVIDER_DISABLED = 'oauth_provider_disabled';
const OAUTH_PROVIDER_UNSUPPORTED = 'oauth_provider_unsupported';
const OAUTH_INVALID_LOGIN_STATE_PARAMS = 'oauth_invalid_login_state_params';
const OAUTH_INVALID_SUCCESS_URL = 'oauth_invalid_success_url';
const OAUTH_INVALID_FAILURE_URL = 'oauth_invalid_failure_url';
const OAUTH_ACCESS_TOKEN_FAILED = 'oauth_access_token_failed';
const OAUTH_MISSING_USER_ID = 'oauth_missing_user_id';
/** Teams */
@ -165,6 +162,9 @@ class Exception extends \Exception
const STORAGE_NOT_WRITABLE = 'storage_not_writable';
const ANTIVIRUS_NOT_AVAILABLE = 'antivirus_not_available';
/** Server Errors */
const GENERAL_SERVER_ERROR = 'general_server_error';
private $errorCode = '';