Skip to content

Commit

Permalink
Merge pull request #7878 from appwrite/string-error-code
Browse files Browse the repository at this point in the history
Handle string error codes
  • Loading branch information
abnegate committed May 1, 2024
2 parents 4378ff2 + 3c3e066 commit 7d7e005
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Appwrite/Extend/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7d7e005

Please sign in to comment.