From acfd6633a22ec2f30df33aa6efd95611d4800cd0 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 28 Mar 2024 14:36:44 +0200 Subject: [PATCH 1/5] non integer errors --- src/Appwrite/Extend/Exception.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 7d56f5a3848..f96057bc5b2 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -296,11 +296,17 @@ 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, $code = null, \Throwable $previous = null) { $this->errors = Config::getParam('errors'); $this->type = $type; $this->code = $code ?? $this->errors[$type]['code']; + + // todo: Handle better PDOExceptions or string errors + if(is_string($this->code)) { + $this->code = 500; + } + $this->message = $message ?? $this->errors[$type]['description']; $this->publish = $this->errors[$type]['publish'] ?? ($this->code >= 500); From c7f2de6500b83a2a89633e229fb702190157bdd1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 30 Apr 2024 12:25:12 +1200 Subject: [PATCH 2/5] Update src/Appwrite/Extend/Exception.php --- src/Appwrite/Extend/Exception.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index f96057bc5b2..458a89deced 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -303,7 +303,7 @@ public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $m $this->code = $code ?? $this->errors[$type]['code']; // todo: Handle better PDOExceptions or string errors - if(is_string($this->code)) { + if(\is_string($this->code) && !\is_numeric($this->code)) { $this->code = 500; } From e6b6e4e54e7b3ef3fbd9b9580d978ce1d7318b9a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 30 Apr 2024 12:25:29 +1200 Subject: [PATCH 3/5] Update src/Appwrite/Extend/Exception.php --- src/Appwrite/Extend/Exception.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 458a89deced..6f89a1d65d0 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -302,7 +302,6 @@ public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $m $this->type = $type; $this->code = $code ?? $this->errors[$type]['code']; - // todo: Handle better PDOExceptions or string errors if(\is_string($this->code) && !\is_numeric($this->code)) { $this->code = 500; } From 9bf13a24005402b7f8c3d43393a06f19c4c9f595 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 30 Apr 2024 12:28:29 +1200 Subject: [PATCH 4/5] Update src/Appwrite/Extend/Exception.php --- src/Appwrite/Extend/Exception.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 6f89a1d65d0..b5e338f1b0b 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -302,8 +302,12 @@ public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $m $this->type = $type; $this->code = $code ?? $this->errors[$type]['code']; - if(\is_string($this->code) && !\is_numeric($this->code)) { - $this->code = 500; + 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']; From 3c3e066bce4549622a62f7caa415784e2e9b4548 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 30 Apr 2024 12:30:35 +1200 Subject: [PATCH 5/5] Update src/Appwrite/Extend/Exception.php --- src/Appwrite/Extend/Exception.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index b5e338f1b0b..851c19a944b 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -296,7 +296,7 @@ class Exception extends \Exception protected array $errors = []; protected bool $publish; - public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, $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;