feat: use general server errors in accounts API
This commit is contained in:
parent
adf103730b
commit
49bfb25df6
|
@ -178,11 +178,6 @@ return [
|
||||||
'description' => 'Cannot create anonymous user when a session is active.',
|
'description' => 'Cannot create anonymous user when a session is active.',
|
||||||
'statusCode' => 401,
|
'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 => [
|
Exception::USER_NOT_FOUND => [
|
||||||
'name' => Exception::USER_NOT_FOUND,
|
'name' => Exception::USER_NOT_FOUND,
|
||||||
'description' => 'User with the requested ID could not be found.',
|
'description' => 'User with the requested ID could not be found.',
|
||||||
|
@ -225,11 +220,6 @@ return [
|
||||||
'description' => 'The chosen OAuth provider is unsupported.',
|
'description' => 'The chosen OAuth provider is unsupported.',
|
||||||
'statusCode' => 501,
|
'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 => [
|
Exception::OAUTH_INVALID_SUCCESS_URL => [
|
||||||
'name' => Exception::OAUTH_INVALID_SUCCESS_URL,
|
'name' => Exception::OAUTH_INVALID_SUCCESS_URL,
|
||||||
'description' => 'Invalid URL received for OAuth success redirect.',
|
'description' => 'Invalid URL received for OAuth success redirect.',
|
||||||
|
@ -240,11 +230,6 @@ return [
|
||||||
'description' => 'Invalid URL received for OAuth failure redirect.',
|
'description' => 'Invalid URL received for OAuth failure redirect.',
|
||||||
'statusCode' => 400,
|
'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 => [
|
Exception::OAUTH_MISSING_USER_ID => [
|
||||||
'name' => Exception::OAUTH_MISSING_USER_ID,
|
'name' => Exception::OAUTH_MISSING_USER_ID,
|
||||||
'description' => 'Failed to obtain user id from the OAuth provider.',
|
'description' => 'Failed to obtain user id from the OAuth provider.',
|
||||||
|
|
|
@ -415,7 +415,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||||
try {
|
try {
|
||||||
$state = \array_merge($defaultState, $oauth2->parseState($state));
|
$state = \array_merge($defaultState, $oauth2->parseState($state));
|
||||||
} catch (\Exception$exception) {
|
} 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 {
|
} else {
|
||||||
$state = $defaultState;
|
$state = $defaultState;
|
||||||
|
@ -437,7 +437,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||||
$response->redirect($state['failure'], 301, 0);
|
$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);
|
$oauth2ID = $oauth2->getUserID($accessToken);
|
||||||
|
@ -705,7 +705,7 @@ App::post('/v1/account/sessions/magic-url')
|
||||||
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
||||||
|
|
||||||
if (false === $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)) {
|
if(empty($url)) {
|
||||||
|
@ -839,7 +839,7 @@ App::put('/v1/account/sessions/magic-url')
|
||||||
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
||||||
|
|
||||||
if (false === $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
|
$audits
|
||||||
|
|
|
@ -28,7 +28,6 @@ class Exception extends \Exception
|
||||||
const USER_COUNT_EXCEEDED = 'user_count_exceeded';
|
const USER_COUNT_EXCEEDED = 'user_count_exceeded';
|
||||||
const USER_ALREADY_EXISTS = 'user_already_exists';
|
const USER_ALREADY_EXISTS = 'user_already_exists';
|
||||||
const USER_BLOCKED = 'user_blocked';
|
const USER_BLOCKED = 'user_blocked';
|
||||||
const USER_CREATION_FAILED = 'user_creation_failed';
|
|
||||||
const USER_INVALID_TOKEN = 'user_invalid_token';
|
const USER_INVALID_TOKEN = 'user_invalid_token';
|
||||||
const USER_NOT_FOUND = 'user_not_found';
|
const USER_NOT_FOUND = 'user_not_found';
|
||||||
const USER_INVALID_CREDENTIALS = 'user_invalid_credentials';
|
const USER_INVALID_CREDENTIALS = 'user_invalid_credentials';
|
||||||
|
@ -46,10 +45,8 @@ class Exception extends \Exception
|
||||||
/** OAuth **/
|
/** OAuth **/
|
||||||
const OAUTH_PROVIDER_DISABLED = 'oauth_provider_disabled';
|
const OAUTH_PROVIDER_DISABLED = 'oauth_provider_disabled';
|
||||||
const OAUTH_PROVIDER_UNSUPPORTED = 'oauth_provider_unsupported';
|
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_SUCCESS_URL = 'oauth_invalid_success_url';
|
||||||
const OAUTH_INVALID_FAILURE_URL = 'oauth_invalid_failure_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';
|
const OAUTH_MISSING_USER_ID = 'oauth_missing_user_id';
|
||||||
|
|
||||||
/** Teams */
|
/** Teams */
|
||||||
|
@ -165,6 +162,9 @@ class Exception extends \Exception
|
||||||
const STORAGE_NOT_WRITABLE = 'storage_not_writable';
|
const STORAGE_NOT_WRITABLE = 'storage_not_writable';
|
||||||
const ANTIVIRUS_NOT_AVAILABLE = 'antivirus_not_available';
|
const ANTIVIRUS_NOT_AVAILABLE = 'antivirus_not_available';
|
||||||
|
|
||||||
|
/** Server Errors */
|
||||||
|
const GENERAL_SERVER_ERROR = 'general_server_error';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private $errorCode = '';
|
private $errorCode = '';
|
||||||
|
|
Loading…
Reference in a new issue