Skip to content

Commit 09853bb

Browse files
committed
Improve exception message
1 parent 4e8f809 commit 09853bb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Formatter/HtmlDataResponseFormatter.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Yiisoft\DataResponse\Formatter;
66

77
use Psr\Http\Message\ResponseInterface;
8+
use RuntimeException;
89
use Yiisoft\DataResponse\DataResponse;
910
use Yiisoft\DataResponse\DataResponseFormatterInterface;
1011
use Yiisoft\DataResponse\HasContentTypeTrait;
@@ -28,7 +29,8 @@ public function format(DataResponse $dataResponse): ResponseInterface
2829
{
2930
$data = $dataResponse->getData();
3031
if (!is_scalar($data) && null !== $data && !$this->isStringableObject($data)) {
31-
throw new \RuntimeException('Data must be a scalar value or null or a stringable object.');
32+
$type = is_object($data) ? get_class($data) : gettype($data);
33+
throw new RuntimeException(sprintf('Data must be a scalar value or null or a stringable object, %s given.', $type));
3234
}
3335

3436
$response = $dataResponse->getResponse();

0 commit comments

Comments
 (0)