Skip to content

Commit 27b9c4c

Browse files
Better exception management for token retrieval.
1 parent 297abaa commit 27b9c4c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Client/OAuthRequestFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ static function (array $data) {
5555
protected function updateToken(RequestInterface $request, callable $method): OAuthTokenInterface
5656
{
5757
$response = $this->client->sendRequest($request);
58+
if (200 !== $response->getStatusCode()) {
59+
throw OAuthAuthenticationException::createFromTokenResponse($response, $this->tokenRequestPath);
60+
}
5861

5962
$content = (string) $response->getBody();
6063
if (!$content) {

Exception/OAuthAuthenticationException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
/**
1313
* Thrown when unable to authenticate against the OAuth server API
1414
*/
15-
class OAuthAuthenticationException extends \RuntimeException
15+
class OAuthAuthenticationException extends RequestFailedException
1616
{
1717
public static function createFromTokenResponse(ResponseInterface $response, string $tokenRequestPath): self
1818
{
1919
$m = "Unable to get OAuth token from remote server '{$tokenRequestPath}': ";
20-
$m .= "{$response->getStatusCode()} {$response->getReasonPhrase()}\n{$response->getBody()}";
20+
$m .= " {$response->getReasonPhrase()}\n";
2121

22-
return new self($m);
22+
return new self($response, $m);
2323
}
2424
}

0 commit comments

Comments
 (0)