diff --git a/app/controllers/general.php b/app/controllers/general.php index d7b1a075c0..620f16f1c1 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -352,19 +352,6 @@ App::error(function (Throwable $error, App $utopia, Request $request, Response $ throw $error; } - if ($error instanceof Appwrite\Extend\Exception) { - // Find error code and error message - - $errors = Config::getParam('errors', []); - $errorData = $errors[$error->getType()]; - - $error = new Appwrite\Extend\Exception( - $errorData['description'] ?? $error->getMessage(), - $errorData['code'] ?? $error->getCode(), - $errorData['name'] ?? $error->getType() - ); - } - if ($logger) { if ($error->getCode() >= 500 || $error->getCode() === 0) { try { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 34480d6bdc..b3984ba6c6 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -2,6 +2,8 @@ namespace Appwrite\Extend; +use Utopia\Config\Config; + class Exception extends \Exception { /** @@ -202,11 +204,24 @@ class Exception extends \Exception private $type = ''; - public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = '', int $code = 0, \Throwable $previous = null) + private string $message = ''; + + private int $code = 0; + + protected array $errors = Config::getParam('errors'); + + public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = '', \Throwable $previous = null) { $this->type = $type; - parent::__construct($message, $code, $previous); + if (isset($this->errors[$type])) { + $this->message = $this->errors[$type]['description']; + $this->code = $this->errors[$type]['code']; + } + + $this->message = $message ?? $this->message; + + parent::__construct($this->message, $this->code, $previous); } /**