From 44f7d85a6446022b565e0e36eea9991b3abd6fd2 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 7 Feb 2022 02:55:53 +0400 Subject: [PATCH] feat: handle utopia exceptions --- app/controllers/general.php | 7 +++++++ src/Appwrite/Extend/Exception.php | 1 + 2 files changed, 8 insertions(+) diff --git a/app/controllers/general.php b/app/controllers/general.php index c243b56b4..25a457842 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -387,6 +387,13 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project, $l throw $error; } + /** Wrap all exceptions inside Appwrite\Extend\Exception */ + if ($error instanceof Utopia\Exception && $error->getCode() === 400) { + $error = new Exception($error->getMessage(), $error->getCode(), Exception::GENERAL_ARGUMENT_INVALID, $error); + } else { + $error = new Exception($error->getMessage(), $error->getCode(), Exception::GENERAL_DEFAULT, $error); + } + $template = ($route) ? $route->getLabel('error', null) : null; if (php_sapi_name() === 'cli') { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index d65bcb2d6..6b4853477 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -151,6 +151,7 @@ class Exception extends \Exception const GENERAL_UNAUTHORIZED_SCOPE = 'general_unauthorized_scope'; const GENERAL_RATE_LIMIT_EXCEEDED = 'general_rate_limit_exceeded'; const GENERAL_SMTP_DISABLED = 'general_smtp_disabled'; + const GENERAL_ARGUMENT_INVALID = 'general_argument_invalid'; const GENERAL_SERVER_ERROR = 'general_server_error';