refactor: address review comment; introduce new exception class

This commit is contained in:
Mustaque Ahmed
2025-10-14 11:35:56 +05:30
parent 367d11785b
commit 52ee23748d
4 changed files with 8 additions and 2 deletions
+5
View File
@@ -497,6 +497,11 @@ return [
'description' => 'The requested file is not publicly readable.',
'code' => 403,
],
Exception::STORAGE_IMAGE_TRANSFORMATIONS_DISABLED => [
'name' => Exception::STORAGE_IMAGE_TRANSFORMATIONS_DISABLED,
'description' => 'Image transformations are disabled for this storage bucket.',
'code' => 401,
],
/** Tokens */
Exception::TOKEN_NOT_FOUND => [
+1 -1
View File
@@ -993,7 +993,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
$allowImageTransformations = $bucket->getAttribute('imageTransformations', true);
if (!$allowImageTransformations && !$isToken) {
// Image transformations are disabled for this bucket
throw new Exception(Exception::USER_UNAUTHORIZED);
throw new Exception(Exception::STORAGE_IMAGE_TRANSFORMATIONS_DISABLED);
}
if ($fileSecurity && !$valid && !$isToken) {
+1 -1
View File
@@ -591,7 +591,7 @@ App::init()
// Only proceed for preview when not disabled; other routes unaffected
// Skip the block for privileged console users and resource tokens.
if ($isImageTransformation && $isImageTransformationsBlocked && !$isPrivilegedUser && !$isToken) {
throw new Exception(Exception::USER_UNAUTHORIZED);
throw new Exception(Exception::STORAGE_IMAGE_TRANSFORMATIONS_DISABLED);
}
if ($bucket->isEmpty() || (!$bucket->getAttribute('enabled') && !$isAppUser && !$isPrivilegedUser)) {
+1
View File
@@ -148,6 +148,7 @@ class Exception extends \Exception
public const STORAGE_INVALID_RANGE = 'storage_invalid_range';
public const STORAGE_INVALID_APPWRITE_ID = 'storage_invalid_appwrite_id';
public const STORAGE_FILE_NOT_PUBLIC = 'storage_file_not_public';
public const STORAGE_IMAGE_TRANSFORMATIONS_DISABLED = 'storage_image_transformations_disabled';
/** VCS */
public const INSTALLATION_NOT_FOUND = 'installation_not_found';