From 6f2ce8469b9d32601ffda5e991870b7ec15988c5 Mon Sep 17 00:00:00 2001 From: Stefano Date: Tue, 21 Jan 2025 09:54:25 +0100 Subject: [PATCH] Update ErrorException.php Fix: Handle cases where $contents is a string instead of an array. Updated constructor to support both array and string types, preventing errors when $contents is not an array. --- src/Exceptions/ErrorException.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Exceptions/ErrorException.php b/src/Exceptions/ErrorException.php index a72a8666..9cb16d3f 100644 --- a/src/Exceptions/ErrorException.php +++ b/src/Exceptions/ErrorException.php @@ -11,16 +11,22 @@ final class ErrorException extends Exception /** * Creates a new Exception instance. * - * @param array{message: string|array, type: ?string, code: string|int|null} $contents + * @param array|string $contents + * @param int $statusCode */ - public function __construct(private readonly array $contents, private readonly int $statusCode) + public function __construct(private readonly array|string $contents, private readonly int $statusCode) { - $message = ($contents['message'] ?: (string) $this->contents['code']) ?: 'Unknown error'; + if(is_string($contents)) { + $message = $contents; + } else { + $message = ($contents['message'] ?: (string) $this->contents['code']) ?: 'Unknown error'; - if (is_array($message)) { - $message = implode(PHP_EOL, $message); + if (is_array($message)) { + $message = implode(PHP_EOL, $message); + } } + parent::__construct($message); }