Skip to content

Commit

Permalink
🔧 provide end user with more accurate status code
Browse files Browse the repository at this point in the history
  • Loading branch information
willpower232 committed Oct 5, 2022
1 parent ab468af commit eda889d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ public function authenticate() : void
]);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$message = 'There was a problem authenticating with the Creditsafe API';
$code = 400;
if ($e->hasResponse()) {
$body = $e->getResponse()->getBody();
$details = json_decode($body, true);
if (json_last_error() === JSON_ERROR_NONE && isset($details['message'])) {
$message = $details['message'];
}
$code = $e->getResponse()->getStatusCode();
}
throw new Exception\Unauthorized($message, 400, $e);
throw new Exception\Unauthorized($message, $code, $e);
}
$decode = json_decode((string) $authenticate->getBody(), true);
$this->setToken($decode['token']);
Expand Down

0 comments on commit eda889d

Please sign in to comment.