mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge pull request #7878 from appwrite/string-error-code
Handle string error codes
This commit is contained in:
commit
7d7e005c00
1 changed files with 10 additions and 1 deletions
|
|
@ -300,11 +300,20 @@ class Exception extends \Exception
|
||||||
protected array $errors = [];
|
protected array $errors = [];
|
||||||
protected bool $publish;
|
protected bool $publish;
|
||||||
|
|
||||||
public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int $code = null, \Throwable $previous = null)
|
public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int|string $code = null, \Throwable $previous = null)
|
||||||
{
|
{
|
||||||
$this->errors = Config::getParam('errors');
|
$this->errors = Config::getParam('errors');
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->code = $code ?? $this->errors[$type]['code'];
|
$this->code = $code ?? $this->errors[$type]['code'];
|
||||||
|
|
||||||
|
if(\is_string($this->code)) {
|
||||||
|
if (\is_numeric($this->code)) {
|
||||||
|
$this->code = (int) $this->code;
|
||||||
|
} else {
|
||||||
|
$this->code = 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->message = $message ?? $this->errors[$type]['description'];
|
$this->message = $message ?? $this->errors[$type]['description'];
|
||||||
|
|
||||||
$this->publish = $this->errors[$type]['publish'] ?? ($this->code >= 500);
|
$this->publish = $this->errors[$type]['publish'] ?? ($this->code >= 500);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue