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

feat: use general server errors in avatars API

This commit is contained in:
Christy Jacob 2022-02-07 00:38:14 +04:00
parent 49bfb25df6
commit c1aed2b64b
3 changed files with 5 additions and 23 deletions

View file

@ -297,21 +297,11 @@ return [
'description' => 'The request avatar could not be found.',
'statusCode' => 404,
],
Exception::IMAGIC_EXTENSION_MISSING => [
'name' => Exception::IMAGIC_EXTENSION_MISSING,
'description' => 'The Imagic extension could not be found.',
'statusCode' => 500,
],
Exception::AVATAR_IMAGE_NOT_FOUND => [
'name' => Exception::AVATAR_IMAGE_NOT_FOUND,
'description' => 'The requested image was not found.',
'statusCode' => 404,
],
Exception::AVATAR_CANNOT_PARSE_IMAGE => [
'name' => Exception::AVATAR_CANNOT_PARSE_IMAGE,
'description' => 'The requested image could not be parsed.',
'statusCode' => 500,
],
Exception::AVATAR_REMOTE_URL_FAILED => [
'name' => Exception::AVATAR_REMOTE_URL_FAILED,
'description' => 'The remote URL could not be fetched.',
@ -349,11 +339,6 @@ return [
'description' => 'The file type is not supported.',
'statusCode' => 400,
],
Exception::STORAGE_FILE_NOT_READABLE => [
'name' => Exception::STORAGE_FILE_NOT_READABLE,
'description' => 'There was an error reading the file from disk.',
'statusCode' => 500,
],
Exception::STORAGE_INVALID_FILE_SIZE => [
'name' => Exception::STORAGE_INVALID_FILE_SIZE,
'description' => 'The file size is either not valid or exceeds the maximum allowed size.',

View file

@ -33,7 +33,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality, $response)
}
if (!\extension_loaded('imagick')) {
throw new Exception('Imagick extension is missing', 500, Exception::IMAGIC_EXTENSION_MISSING);
throw new Exception('Imagick extension is missing', 500, Exception::GENERAL_SERVER_ERROR);
}
$output = 'png';
@ -43,7 +43,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality, $response)
$type = 'png';
if (!\is_readable($path)) {
throw new Exception('File not readable in ' . $path, 500, Exception::STORAGE_FILE_NOT_READABLE);
throw new Exception('File not readable in ' . $path, 500, Exception::GENERAL_SERVER_ERROR);
}
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . '/app-0')); // Limit file number or size
@ -169,7 +169,7 @@ App::get('/v1/avatars/image')
}
if (!\extension_loaded('imagick')) {
throw new Exception('Imagick extension is missing', 500, Exception::IMAGIC_EXTENSION_MISSING);
throw new Exception('Imagick extension is missing', 500, Exception::GENERAL_SERVER_ERROR);
}
$fetch = @\file_get_contents($url, false);
@ -181,7 +181,7 @@ App::get('/v1/avatars/image')
try {
$image = new Image($fetch);
} catch (\Exception$exception) {
throw new Exception('Unable to parse image', 500, Exception::AVATAR_CANNOT_PARSE_IMAGE);
throw new Exception('Unable to parse image', 500, Exception::GENERAL_SERVER_ERROR);
}
$image->crop((int) $width, (int) $height);
@ -238,7 +238,7 @@ App::get('/v1/avatars/favicon')
}
if (!\extension_loaded('imagick')) {
throw new Exception('Imagick extension is missing', 500, Exception::IMAGIC_EXTENSION_MISSING);
throw new Exception('Imagick extension is missing', 500, Exception::GENERAL_SERVER_ERROR);
}
$curl = \curl_init();

View file

@ -65,9 +65,7 @@ class Exception extends \Exception
/** Avatars */
const AVATAR_SET_NOT_FOUND = 'avatar_set_not_found';
const AVATAR_NOT_FOUND = 'avatar_not_found';
const IMAGIC_EXTENSION_MISSING = 'imagic_extension_missing';
const AVATAR_IMAGE_NOT_FOUND = 'avatar_image_not_found';
const AVATAR_CANNOT_PARSE_IMAGE = 'avatar_cannot_parse_image';
const AVATAR_REMOTE_URL_FAILED = 'avatar_remote_url_failed';
const AVATAR_ICON_NOT_FOUND = 'avatar_icon_not_found';
@ -76,7 +74,6 @@ class Exception extends \Exception
const STORAGE_FILE_NOT_FOUND = 'storage_file_not_found';
const STORAGE_DEVICE_NOT_FOUND = 'storage_device_not_found';
const STORAGE_FILE_DELETION_FAILED = 'storage_file_deletion_failed';
const STORAGE_FILE_NOT_READABLE = 'storage_file_not_readable';
const STORAGE_FILE_EMPTY = 'storage_file_empty';
const STORAGE_FILE_TYPE_UNSUPPORTED = 'storage_file_type_unsupported';
const STORAGE_INVALID_FILE_SIZE = 'storage_invalid_file_size';