Skip to content

Commit

Permalink
Merge pull request #24 from eventfarm/feature/improve-logging-around-…
Browse files Browse the repository at this point in the history
…oauth

Improved Logging Around unable to load access token
  • Loading branch information
toddcornett authored Apr 27, 2021
2 parents 6dc6bf0 + f1d415d commit 178440e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Rest/OAuthRestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ private function getRefreshToken(string $refreshToken): OAuthAccessToken
private function getOAuthAccessTokenFromResponse(ResponseInterface $response): OAuthAccessToken
{
if ($response->getStatusCode() !== 200) {
throw OAuthRestClientException::unableToLoadAccessToken();
$message = '(' . $response->getStatusCode() . ') ' . $response->getBody()->__toString();
throw OAuthRestClientException::unableToLoadAccessToken($message);
}

$response = json_decode($response->getBody()->__toString(), true);
Expand Down
10 changes: 8 additions & 2 deletions src/Rest/OAuthRestClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

class OAuthRestClientException extends Exception
{
public static function unableToLoadAccessToken()
public static function unableToLoadAccessToken(?string $message = null)
{
return new self('Unable to load access token');
$errorMessage = 'Unable to load access token';

if ($message) {
$errorMessage . ': ' . $message;
}

return new self($errorMessage);
}
}

0 comments on commit 178440e

Please sign in to comment.