diff --git a/app/controllers/general.php b/app/controllers/general.php index e05b57485c..55517fff93 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -376,11 +376,13 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project, $l } /** 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 { + if (!($error instanceof Exception)) { $error = new Exception($error->getMessage(), $error->getCode(), Exception::GENERAL_UNKNOWN, $error); } + + if ($error instanceof Utopia\Exception && $error->getCode() === 400) { + $error->setType(Exception::GENERAL_ARGUMENT_INVALID); + } $template = ($route) ? $route->getLabel('error', null) : null; diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 0db0c5ed6b..5b05551b43 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -159,10 +159,25 @@ class Exception extends \Exception } /** + * Get the type of the exception. + * * @return string */ public function getType(): string { return $this->type; } + + /** + * Set the type of the exception. + * + * @param string $type + * + * @return void + */ + public function setType(string $type): void + { + $this->type = $type; + } + } \ No newline at end of file