Skip to content

Commit

Permalink
CLI-1026: Catch malformed responses (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored May 2, 2023
1 parent 8a019d6 commit 06fa9c8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Connector/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AcquiaCloudApi\Connector;

use http\Exception\RuntimeException;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\BadResponseException;
use AcquiaCloudApi\Exception\ApiErrorException;
Expand Down Expand Up @@ -152,7 +153,15 @@ public function processResponse(ResponseInterface $response): mixed
{

$body_json = $response->getBody();
$body = json_decode($body_json);
$body = json_decode($body_json, null, 512, JSON_THROW_ON_ERROR);
if (is_null($body)) {
throw new RuntimeException(
'Response contained an empty body. Status '
. $response->getStatusCode()
. '. Request ID '
. $response->getHeaderLine('X-Request-Id')
);
}

if (property_exists($body, '_embedded') && property_exists($body->_embedded, 'items')) {
return $body->_embedded->items;
Expand Down

0 comments on commit 06fa9c8

Please sign in to comment.