Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Support string input for $contents in Exception constructor #511

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/Exceptions/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ final class ErrorException extends Exception
/**
* Creates a new Exception instance.
*
* @param array{message: string|array<int, string>, 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);
}

Expand Down