Skip to content

Commit dd4098c

Browse files
committed
Fix "PHP Warning: Array to string conversion"
1 parent 3310abd commit dd4098c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Http/ClientPlugin/ErrorPlugin.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
use Psr\Http\Message\RequestInterface;
2222
use Psr\Http\Message\ResponseInterface;
2323

24+
use function count;
2425
use function is_array;
26+
use function sprintf;
2527

2628
/**
2729
* Class ErrorPlugin.
@@ -138,13 +140,22 @@ private function handleUnprocessableEntity(RequestInterface $request, ResponseIn
138140
throw new ClientErrorException($response->getReasonPhrase(), $request, $response);
139141
}
140142

141-
$errorKey = key($errorResponse);
142-
$errorValue = current($errorResponse);
143+
$errorKey = key($errorResponse);
144+
$errorValue = current($errorResponse);
145+
$messageContent = $errorValue;
146+
147+
if (is_array($errorValue)) {
148+
if (count($errorValue) === count($errorValue, COUNT_RECURSIVE)) {
149+
$messageContent = implode('" or "', $errorValue);
150+
} else {
151+
$messageContent = serialize($errorValue);
152+
}
153+
}
143154

144155
$errorMessage = sprintf(
145156
'The entity "%s" failed with "%s".',
146157
$errorKey,
147-
is_array($errorValue) ? implode('" or "', $errorValue) : $errorValue
158+
$messageContent
148159
);
149160

150161
throw new DetailedErrorException(

0 commit comments

Comments
 (0)