1
0
Fork 0
mirror of synced 2024-06-01 10:29:48 +12:00

Merge pull request #7878 from appwrite/string-error-code

Handle string error codes
This commit is contained in:
Jake Barnby 2024-05-01 19:50:23 +12:00 committed by GitHub
commit 7d7e005c00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -300,11 +300,20 @@ class Exception extends \Exception
protected array $errors = [];
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->type = $type;
$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->publish = $this->errors[$type]['publish'] ?? ($this->code >= 500);