Skip to content

Commit

Permalink
CLI-1273: Cryptic errors for 500 responses
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Apr 16, 2024
1 parent b729779 commit 27683b2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Connector/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function modifyOptions(): array
*/
public function request(string $verb, string $path, array $options = []): mixed
{
// Put options sent with API calls into a property so they can be accessed
// Put options sent with API calls into a property, so they can be accessed
// and therefore tested in tests.
$this->requestOptions = $options;

Expand Down Expand Up @@ -151,7 +151,15 @@ public function makeRequest(string $verb, string $path, array $options = []): Re
*/
public function processResponse(ResponseInterface $response): mixed
{

// Internal server errors return HTML instead of JSON, breaking our parsing.
if ($response->getStatusCode() === 500) {
throw new RuntimeException(
'Cloud API internal server error. Status '
. $response->getStatusCode()
. '. Request ID '
. $response->getHeaderLine('X-Request-Id')
);
}
$body_json = $response->getBody();
$body = json_decode($body_json, null, 512, JSON_THROW_ON_ERROR);
if (is_null($body)) {
Expand Down

0 comments on commit 27683b2

Please sign in to comment.