From e80412d825c08c8d2e6c6042aa1c7b7fa6c64f7c Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 25 Nov 2023 19:59:41 +0100 Subject: [PATCH] Accept `Throwable` as rejection reason --- CHANGELOG.md | 6 ++++++ src/FulfilledPromise.php | 4 ++-- src/RejectedPromise.php | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fafc207..1618b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 1.2.2 + +### Fixed + +- Fix accepting `Throwable` as rejection reason of a promise + ## 1.2.1 ### Added diff --git a/src/FulfilledPromise.php b/src/FulfilledPromise.php index c9158e7..45c4551 100644 --- a/src/FulfilledPromise.php +++ b/src/FulfilledPromise.php @@ -37,8 +37,8 @@ public function then(callable $onFulfilled = null, callable $onRejected = null) try { return new self($onFulfilled($this->result)); - } catch (\Exception $e) { - return new RejectedPromise($e); + } catch (\Throwable $exception) { + return new RejectedPromise($exception); } } diff --git a/src/RejectedPromise.php b/src/RejectedPromise.php index a500048..c093a55 100644 --- a/src/RejectedPromise.php +++ b/src/RejectedPromise.php @@ -14,11 +14,11 @@ final class RejectedPromise implements Promise { /** - * @var \Exception + * @var \Throwable */ private $exception; - public function __construct(\Exception $exception) + public function __construct(\Throwable $exception) { $this->exception = $exception; } @@ -34,8 +34,8 @@ public function then(callable $onFulfilled = null, callable $onRejected = null) try { return new FulfilledPromise($onRejected($this->exception)); - } catch (\Exception $e) { - return new self($e); + } catch (\Throwable $exception) { + return new self($exception); } }