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
-15
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.',
+5 -5
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();