mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Move default message and code handling into exception
This commit is contained in:
parent
40022decb4
commit
4da9273b28
2 changed files with 17 additions and 15 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue