Skip to content

Commit

Permalink
Update error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
harm-smits committed Dec 6, 2021
1 parent 98586c5 commit 516c94c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,14 @@ private function handleResponse(?ResponseInterface &$response, &$responseFormat,
$body = $filter ? $filter($body) : $body;
return $this->populator->populate($responseFormat[$response->getStatusCode()], $body);
} elseif ($response->getStatusCode() !== 200) {
throw new Exception\RequestException('Erroneous error value');
$body = json_decode($response->getBody(), true);
$message = 'Unknown API error';

if (!empty($body['error']['message'])) {
$message = $body['error']['message'];
}

throw new Exception\RequestException($message);
} else {
return $response->getBody();
}
Expand Down

0 comments on commit 516c94c

Please sign in to comment.