feat: exceptions on more files
This commit is contained in:
parent
662bfe0ab8
commit
a5bc0a61ca
|
@ -222,13 +222,6 @@ return [
|
|||
'description' => 'The invite does not belong to the current user.',
|
||||
'code' => 401,
|
||||
],
|
||||
Exception::TEAM_ID_MISMATCH => [
|
||||
'name' => Exception::TEAM_ID_MISMATCH,
|
||||
'description' => 'Team IDs don\'t match',
|
||||
'code' => 404,
|
||||
],
|
||||
|
||||
|
||||
|
||||
/** Membership */
|
||||
Exception::MEMBERSHIP_NOT_FOUND => [
|
||||
|
@ -287,12 +280,12 @@ return [
|
|||
],
|
||||
Exception::STORAGE_FILE_TYPE_UNSUPPORTED => [
|
||||
'name' => Exception::STORAGE_FILE_TYPE_UNSUPPORTED,
|
||||
'description' => 'The file type is not supported.',
|
||||
'description' => 'The given file extension is not supported.',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::STORAGE_INVALID_FILE_SIZE => [
|
||||
'name' => Exception::STORAGE_INVALID_FILE_SIZE,
|
||||
'description' => 'File size not allowed',
|
||||
'description' => 'The file size is either not valid or exceeds the maximum allowed size. Please check the file or the value of the _APP_STORAGE_LIMIT environment variable.',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::STORAGE_INVALID_FILE => [
|
||||
|
@ -364,6 +357,7 @@ return [
|
|||
'code' => 404,
|
||||
],
|
||||
|
||||
/** Databases */
|
||||
Exception::DATABASE_NOT_FOUND => [
|
||||
'name' => Exception::DATABASE_NOT_FOUND,
|
||||
'description' => 'Database not found',
|
||||
|
@ -438,7 +432,7 @@ return [
|
|||
],
|
||||
Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED => [
|
||||
'name' => Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED,
|
||||
'description' => 'Cannot set default value for array attributes',
|
||||
'description' => 'Default values cannot be set for <span class="tag">array</span> and <span class="tag">required</span> attributes.',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::ATTRIBUTE_ALREADY_EXISTS => [
|
||||
|
@ -545,91 +539,4 @@ return [
|
|||
'description' => 'Domain verification for the requested domain has failed.',
|
||||
'code' => 401,
|
||||
],
|
||||
|
||||
/** Mocks */
|
||||
Exception::MOCK_INVALID_CONTENT_RANGE_HEADER => [
|
||||
'name' => Exception::MOCK_INVALID_CONTENT_RANGE_HEADER,
|
||||
'description' => 'Invalid content-range header',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_FIRST_CHUNK_CANNOT_HAVE_ID => [
|
||||
'name' => Exception::MOCK_FIRST_CHUNK_CANNOT_HAVE_ID,
|
||||
'description' => 'First chunked request cannot have id header',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_CHUNK_MISSING_ID => [
|
||||
'name' => Exception::MOCK_CHUNK_MISSING_ID,
|
||||
'description' => 'All chunked request must have id header (except first)',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_CHUNK_INVALID_SIZE => [
|
||||
'name' => Exception::MOCK_CHUNK_INVALID_SIZE,
|
||||
'description' => 'Chunk size must be 5MB (except last chunk)',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_INVALID_FILE_NAME => [
|
||||
'name' => Exception::MOCK_INVALID_FILE_NAME,
|
||||
'description' => 'Wrong file name',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_INVALID_FILE_SIZE => [
|
||||
'name' => Exception::MOCK_INVALID_FILE_SIZE,
|
||||
'description' => 'Wrong file size',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_WRONG_FILE_UPLOADED => [
|
||||
'name' => Exception::MOCK_WRONG_FILE_UPLOADED,
|
||||
'description' => 'Wrong file uploaded',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_MISSING_COOKIE => [
|
||||
'name' => Exception::MOCK_MISSING_COOKIE,
|
||||
'description' => 'Missing cookie value',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_INVALID_CLIENT_ID => [
|
||||
'name' => Exception::MOCK_INVALID_CLIENT_ID,
|
||||
'description' => 'Invalid client ID',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_INVALID_CLIENT_SECRET => [
|
||||
'name' => Exception::MOCK_INVALID_CLIENT_SECRET,
|
||||
'description' => 'Invalid client secret',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_INVALID_TOKEN => [
|
||||
'name' => Exception::MOCK_INVALID_TOKEN,
|
||||
'description' => 'Invalid token',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_INVALID_REFRESH_TOKEN => [
|
||||
'name' => Exception::MOCK_INVALID_REFRESH_TOKEN,
|
||||
'description' => 'Invalid refresh token',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_INVALID_GRANT_TYPE => [
|
||||
'name' => Exception::MOCK_INVALID_GRANT_TYPE,
|
||||
'description' => 'Invalid grant type',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_FAILED_TO_READ_RESULTS => [
|
||||
'name' => Exception::MOCK_FAILED_TO_READ_RESULTS,
|
||||
'description' => 'Failed to read results',
|
||||
'code' => 500,
|
||||
],
|
||||
Exception::MOCK_FAILED_TO_SAVE_RESULTS => [
|
||||
'name' => Exception::MOCK_FAILED_TO_SAVE_RESULTS,
|
||||
'description' => 'Failed to save results',
|
||||
'code' => 500,
|
||||
],
|
||||
Exception::MOCK_400 => [
|
||||
'name' => Exception::MOCK_400,
|
||||
'description' => 'Mock 400 error',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::MOCK_500 => [
|
||||
'name' => Exception::MOCK_500,
|
||||
'description' => 'Mock 500 error',
|
||||
'code' => 500,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -312,7 +312,7 @@ App::get('/v1/avatars/favicon')
|
|||
$data = @\file_get_contents($outputHref, false);
|
||||
|
||||
if (empty($data) || (\mb_substr($data, 0, 5) === '<html') || \mb_substr($data, 0, 5) === '<!doc') {
|
||||
throw new Exception(Exception::AVATAR_ICON_NOT_FOUND);
|
||||
throw new Exception(Exception::AVATAR_ICON_NOT_FOUND, 'Favicon not found');
|
||||
}
|
||||
|
||||
$cache->save($key, $data);
|
||||
|
|
|
@ -84,11 +84,11 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
|
|||
|
||||
// Must throw here since dbForProject->createAttribute is performed by db worker
|
||||
if ($required && $default) {
|
||||
throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED);
|
||||
throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for required attribute');
|
||||
}
|
||||
|
||||
if ($array && $default) {
|
||||
throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED);
|
||||
throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for array attribute');
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -184,7 +184,7 @@ App::post('/v1/databases')
|
|||
|
||||
$collections = Config::getParam('collections', [])['collections'] ?? [];
|
||||
if (empty($collections)) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Collections collection is not configured.');
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'The "collections" collection is not configured.');
|
||||
}
|
||||
|
||||
$attributes = [];
|
||||
|
|
|
@ -826,11 +826,11 @@ App::post('/v1/functions/:functionId/executions')
|
|||
$deployment = Authorization::skip(fn () => $dbForProject->getDocument('deployments', $function->getAttribute('deployment', '')));
|
||||
|
||||
if ($deployment->getAttribute('resourceId') !== $function->getId()) {
|
||||
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
|
||||
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND, 'Deployment not found. Create a deployment before trying to execute a function');
|
||||
}
|
||||
|
||||
if ($deployment->isEmpty()) {
|
||||
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
|
||||
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND, 'Deployment not found. Create a deployment before trying to execute a function');
|
||||
}
|
||||
|
||||
/** Check if build has completed */
|
||||
|
|
|
@ -19,6 +19,6 @@ App::post('/v1/graphql')
|
|||
->label('scope', 'public')
|
||||
->action(
|
||||
function () {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'GraphQL support is coming soon!');
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'GraphQL support is coming soon!', 503);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -302,7 +302,7 @@ App::delete('/v1/storage/buckets/:bucketId')
|
|||
}
|
||||
|
||||
if (!$dbForProject->deleteDocument('buckets', $bucketId)) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove project from DB');
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove bucket from DB');
|
||||
}
|
||||
|
||||
$deletes
|
||||
|
@ -452,7 +452,7 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
|||
// Check if file size is exceeding allowed limit
|
||||
$fileSizeValidator = new FileSize($maximumFileSize);
|
||||
if (!$fileSizeValidator->isValid($fileSize)) {
|
||||
throw new Exception(Exception::STORAGE_INVALID_FILE_SIZE);
|
||||
throw new Exception(Exception::STORAGE_INVALID_FILE_SIZE, 'File size not allowed');
|
||||
}
|
||||
|
||||
$upload = new Upload();
|
||||
|
|
|
@ -320,7 +320,7 @@ App::post('/v1/teams/:teamId/memberships')
|
|||
$total = $dbForProject->count('users', [], APP_LIMIT_USERS);
|
||||
|
||||
if ($total >= $limit) {
|
||||
throw new Exception(Exception::USER_COUNT_EXCEEDED);
|
||||
throw new Exception(Exception::USER_COUNT_EXCEEDED, 'Project registration is restricted. Contact your administrator for more information.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -782,7 +782,7 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId')
|
|||
}
|
||||
|
||||
if ($membership->getAttribute('teamId') !== $teamId) {
|
||||
throw new Exception(Exception::TEAM_ID_MISMATCH);
|
||||
throw new Exception(Exception::TEAM_MEMBERSHIP_MISMATCH);
|
||||
}
|
||||
|
||||
$user = $dbForProject->getDocument('users', $membership->getAttribute('userId'));
|
||||
|
|
|
@ -239,7 +239,7 @@ App::init()
|
|||
&& $route->getLabel('origin', false) !== '*'
|
||||
&& empty($request->getHeader('x-appwrite-key', ''))
|
||||
) {
|
||||
throw new AppwriteException(AppwriteException::GENERAL_UNKNOWN_ORIGIN, $originValidator->getDescription(), 403);
|
||||
throw new AppwriteException(AppwriteException::GENERAL_UNKNOWN_ORIGIN, $originValidator->getDescription());
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -253,31 +253,31 @@ App::post('/v1/mock/tests/general/upload')
|
|||
$file['size'] = (\is_array($file['size'])) ? $file['size'][0] : $file['size'];
|
||||
|
||||
if (is_null($start) || is_null($end) || is_null($size)) {
|
||||
throw new Exception(Exception::GENERAL_MOCK);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Invalid content-range header');
|
||||
}
|
||||
|
||||
if ($start > $end || $end > $size) {
|
||||
throw new Exception(Exception::GENERAL_MOCK);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Invalid content-range header');
|
||||
}
|
||||
|
||||
if ($start === 0 && !empty($id)) {
|
||||
throw new Exception(Exception::GENERAL_MOCK);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'First chunked request cannot have id header');
|
||||
}
|
||||
|
||||
if ($start !== 0 && $id !== 'newfileid') {
|
||||
throw new Exception(Exception::GENERAL_MOCK);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'All chunked request must have id header (except first)');
|
||||
}
|
||||
|
||||
if ($end !== $size && $end - $start + 1 !== $chunkSize) {
|
||||
throw new Exception(Exception::GENERAL_MOCK);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Chunk size must be 5MB (except last chunk)');
|
||||
}
|
||||
|
||||
if ($end !== $size && $file['size'] !== $chunkSize) {
|
||||
throw new Exception(Exception::GENERAL_MOCK);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Wrong chunk size');
|
||||
}
|
||||
|
||||
if ($file['size'] > $chunkSize) {
|
||||
throw new Exception(Exception::GENERAL_MOCK);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Chunk size must be 5MB or less');
|
||||
}
|
||||
|
||||
if ($end !== $size) {
|
||||
|
@ -293,15 +293,15 @@ App::post('/v1/mock/tests/general/upload')
|
|||
$file['size'] = (\is_array($file['size'])) ? $file['size'][0] : $file['size'];
|
||||
|
||||
if ($file['name'] !== 'file.png') {
|
||||
throw new Exception(Exception::MOCK_INVALID_FILE_NAME);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Wrong file name');
|
||||
}
|
||||
|
||||
if ($file['size'] !== 38756) {
|
||||
throw new Exception(Exception::MOCK_INVALID_FILE_SIZE);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Wrong file size');
|
||||
}
|
||||
|
||||
if (\md5(\file_get_contents($file['tmp_name'])) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
|
||||
throw new Exception(Exception::MOCK_WRONG_FILE_UPLOADED);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Wrong file uploaded');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -374,7 +374,7 @@ App::get('/v1/mock/tests/general/get-cookie')
|
|||
->action(function (Request $request) {
|
||||
|
||||
if ($request->getCookie('cookieName', '') !== 'cookieValue') {
|
||||
throw new Exception(Exception::MOCK_MISSING_COOKIE);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Missing cookie value');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -408,7 +408,7 @@ App::get('/v1/mock/tests/general/400-error')
|
|||
->label('sdk.response.model', Response::MODEL_ERROR)
|
||||
->label('sdk.mock', true)
|
||||
->action(function () {
|
||||
throw new Exception(Exception::MOCK_400);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Mock 400 error');
|
||||
});
|
||||
|
||||
App::get('/v1/mock/tests/general/500-error')
|
||||
|
@ -424,7 +424,7 @@ App::get('/v1/mock/tests/general/500-error')
|
|||
->label('sdk.response.model', Response::MODEL_ERROR)
|
||||
->label('sdk.mock', true)
|
||||
->action(function () {
|
||||
throw new Exception(Exception::MOCK_500);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Mock 500 error', 500);
|
||||
});
|
||||
|
||||
App::get('/v1/mock/tests/general/502-error')
|
||||
|
@ -480,11 +480,11 @@ App::get('/v1/mock/tests/general/oauth2/token')
|
|||
->action(function (string $client_id, string $client_secret, string $grantType, string $redirectURI, string $code, string $refreshToken, Response $response) {
|
||||
|
||||
if ($client_id != '1') {
|
||||
throw new Exception(Exception::MOCK_INVALID_CLIENT_ID);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Invalid client ID');
|
||||
}
|
||||
|
||||
if ($client_secret != '123456') {
|
||||
throw new Exception(Exception::MOCK_INVALID_CLIENT_SECRET);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Invalid client secret');
|
||||
}
|
||||
|
||||
$responseJson = [
|
||||
|
@ -495,18 +495,18 @@ App::get('/v1/mock/tests/general/oauth2/token')
|
|||
|
||||
if ($grantType === 'authorization_code') {
|
||||
if ($code !== 'abcdef') {
|
||||
throw new Exception(Exception::MOCK_INVALID_TOKEN);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Invalid token');
|
||||
}
|
||||
|
||||
$response->json($responseJson);
|
||||
} elseif ($grantType === 'refresh_token') {
|
||||
if ($refreshToken !== 'tuvwxyz') {
|
||||
throw new Exception(Exception::MOCK_INVALID_REFRESH_TOKEN);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Invalid refresh token');
|
||||
}
|
||||
|
||||
$response->json($responseJson);
|
||||
} else {
|
||||
throw new Exception(Exception::MOCK_INVALID_GRANT_TYPE);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Invalid grant type');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -520,7 +520,7 @@ App::get('/v1/mock/tests/general/oauth2/user')
|
|||
->action(function (string $token, Response $response) {
|
||||
|
||||
if ($token != '123456') {
|
||||
throw new Exception(Exception::MOCK_INVALID_TOKEN);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Invalid token');
|
||||
}
|
||||
|
||||
$response->json([
|
||||
|
@ -571,7 +571,7 @@ App::shutdown()
|
|||
$tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : [];
|
||||
|
||||
if (!\is_array($tests)) {
|
||||
throw new Exception(Exception::MOCK_FAILED_TO_READ_RESULTS);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Failed to read results', 500);
|
||||
}
|
||||
|
||||
$result[$route->getMethod() . ':' . $route->getPath()] = true;
|
||||
|
@ -579,7 +579,7 @@ App::shutdown()
|
|||
$tests = \array_merge($tests, $result);
|
||||
|
||||
if (!\file_put_contents($path, \json_encode($tests), LOCK_EX)) {
|
||||
throw new Exception(Exception::MOCK_FAILED_TO_SAVE_RESULTS);
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Failed to save results', 500);
|
||||
}
|
||||
|
||||
$response->dynamic(new Document(['result' => $route->getMethod() . ':' . $route->getPath() . ':passed']), Response::MODEL_MOCK);
|
||||
|
|
|
@ -31,7 +31,6 @@ class Exception extends \Exception
|
|||
* - Keys
|
||||
* - Platform
|
||||
* - Domain
|
||||
* - Mocks
|
||||
*/
|
||||
|
||||
/** General */
|
||||
|
@ -81,7 +80,6 @@ class Exception extends \Exception
|
|||
public const TEAM_INVALID_SECRET = 'team_invalid_secret';
|
||||
public const TEAM_MEMBERSHIP_MISMATCH = 'team_membership_mismatch';
|
||||
public const TEAM_INVITE_MISMATCH = 'team_invite_mismatch';
|
||||
public const TEAM_ID_MISMATCH = 'team_id_mismatch';
|
||||
|
||||
/** Membership */
|
||||
public const MEMBERSHIP_NOT_FOUND = 'membership_not_found';
|
||||
|
@ -175,25 +173,6 @@ class Exception extends \Exception
|
|||
public const DOMAIN_ALREADY_EXISTS = 'domain_already_exists';
|
||||
public const DOMAIN_VERIFICATION_FAILED = 'domain_verification_failed';
|
||||
|
||||
/** Mocks */
|
||||
public const MOCK_INVALID_CONTENT_RANGE_HEADER = 'mock_invalid_content_range_header';
|
||||
public const MOCK_FIRST_CHUNK_CANNOT_HAVE_ID = 'mock_first_chunk_cannot_have_id';
|
||||
public const MOCK_CHUNK_MISSING_ID = 'mock_chunk_missing_id';
|
||||
public const MOCK_CHUNK_INVALID_SIZE = 'mock_chunk_invalid_size';
|
||||
public const MOCK_INVALID_FILE_NAME = 'mock_invalid_file_name';
|
||||
public const MOCK_INVALID_FILE_SIZE = 'mock_invalid_file_size';
|
||||
public const MOCK_WRONG_FILE_UPLOADED = 'mock_wrong_file_uploaded';
|
||||
public const MOCK_MISSING_COOKIE = 'mock_missing_cookie';
|
||||
public const MOCK_INVALID_CLIENT_ID = 'mock_invalid_client_id';
|
||||
public const MOCK_INVALID_CLIENT_SECRET = 'mock_invalid_client_secret';
|
||||
public const MOCK_INVALID_TOKEN = 'mock_invalid_token';
|
||||
public const MOCK_INVALID_REFRESH_TOKEN = 'mock_invalid_refresh_token';
|
||||
public const MOCK_INVALID_GRANT_TYPE = 'mock_invalid_grant_type';
|
||||
public const MOCK_FAILED_TO_READ_RESULTS = 'mock_failed_to_read_results';
|
||||
public const MOCK_FAILED_TO_SAVE_RESULTS = 'mock_failed_to_save_results';
|
||||
public const MOCK_400 = 'mock_400';
|
||||
public const MOCK_500 = 'mock_500';
|
||||
|
||||
protected $type = '';
|
||||
|
||||
protected static array $errors = Config::getParam('errors');
|
||||
|
|
Loading…
Reference in a new issue