Skip to content

Commit

Permalink
Cleanup some refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed May 8, 2019
1 parent 0380ea0 commit ecf9c45
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Client/Partner.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface
$request = $request->withHeader('User-Agent', $applicationName);
}

foreach (['PASS1', 'PASS2'] as $pass) {
foreach ([1, 2] as $pass) {
if ($refreshRequired) {
$this->refreshToken();
}
Expand Down Expand Up @@ -75,7 +75,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface
&& $oAuthProblem === static::OAUTH_PROBLEM_TOKEN_EXPIRED
) {
// The token has expired and should be renewed.
// Try a second pass, renewing the token first.
// Try a second pass, renewing the token on the way through.

$refreshRequired = true;
continue;
Expand All @@ -84,7 +84,8 @@ public function sendRequest(RequestInterface $request): ResponseInterface
// TODO: handle this with custom exception.

throw new RuntimeException(sprintf(
'OAuth access error: %s (%s)',
'OAuth access error on pass %d: %s (%s)',
$pass,
$oAuthProblem,
$oAuthData['oauth_problem_advice'] ?? ''
));
Expand All @@ -94,15 +95,16 @@ public function sendRequest(RequestInterface $request): ResponseInterface
// generate our own custom payload with the error details?
throw new RuntimeException(sprintf(
'Error: %d (%s)',
'Error on pass %d: %d (%s)',
$pass,
$response->getStatusCode(),
$otherProblem
));
}
}

// If we got here without finding an OAuth or other error,
// then we have a usable response. Don't do a second pass.
// then we have a usable response. Don't do another pass.

break;
}
Expand Down

0 comments on commit ecf9c45

Please sign in to comment.