diff --git a/src/IteratorRejectionResultBucket.php b/src/IteratorRejectionResultBucket.php index bcba909..e3f28f2 100644 --- a/src/IteratorRejectionResultBucket.php +++ b/src/IteratorRejectionResultBucket.php @@ -16,7 +16,7 @@ /** @param \Iterator $iterator */ public function __construct( private string $reason, - private \Throwable $exception, + private ?\Throwable $exception, private \Iterator $iterator, ) {} @@ -27,6 +27,9 @@ public function reasons(): ?array public function exceptions(): ?array { + if ($this->exception === null) { + return null; + } return [$this->exception]; } diff --git a/src/RejectionResultBucket.php b/src/RejectionResultBucket.php index 925122f..d8e8b80 100644 --- a/src/RejectionResultBucket.php +++ b/src/RejectionResultBucket.php @@ -19,7 +19,7 @@ final class RejectionResultBucket implements Contract\RejectionResultBucketInter /** @param Type ...$values */ public function __construct( private readonly string $reason, - private readonly \Throwable $exception, + private readonly ?\Throwable $exception, ...$values, ) { $this->values = array_values($values); @@ -32,6 +32,10 @@ public function reasons(): ?array public function exceptions(): ?array { + if ($this->exception === null) { + return null; + } + return [$this->exception]; }