From a20f71c511becb2132b499de69af1b982c6dc721 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 1 Sep 2025 13:08:17 +0530 Subject: [PATCH] chore: update exception thrown when svg sanitization fails --- app/config/errors.php | 5 +++++ app/controllers/api/avatars.php | 2 +- src/Appwrite/Extend/Exception.php | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/config/errors.php b/app/config/errors.php index 23df60f4ba..c4617f1cde 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -435,6 +435,11 @@ return [ 'description' => 'The requested favicon could not be found.', 'code' => 404, ], + Exception::AVATAR_SVG_SANITIZATION_FAILED => [ + 'name' => Exception::AVATAR_SVG_SANITIZATION_FAILED, + 'description' => 'SVG sanitization failed.', + 'code' => 400, + ], /** Storage */ Exception::STORAGE_FILE_ALREADY_EXISTS => [ diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 785324739b..90364d997e 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -474,7 +474,7 @@ App::get('/v1/avatars/favicon') $sanitizer->minify(true); $cleanSvg = $sanitizer->sanitize($data); if ($cleanSvg === false) { - throw new \Exception('SVG sanitization failed'); + throw new Exception(Exception::AVATAR_SVG_SANITIZATION_FAILED); } $response ->addHeader('Cache-Control', 'private, max-age=2592000') // 30 days diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 8eded2dbe0..9849352e56 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -134,6 +134,7 @@ class Exception extends \Exception public const AVATAR_IMAGE_NOT_FOUND = 'avatar_image_not_found'; public const AVATAR_REMOTE_URL_FAILED = 'avatar_remote_url_failed'; public const AVATAR_ICON_NOT_FOUND = 'avatar_icon_not_found'; + public const AVATAR_SVG_SANITIZATION_FAILED = 'avatar_svg_sanitization_failed'; /** Storage */ public const STORAGE_FILE_ALREADY_EXISTS = 'storage_file_already_exists';