Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
* 2.x:
  ExceptionThrower: adjust rate limit detection
  • Loading branch information
acrobat committed Mar 11, 2021
2 parents 0e09516 + 89f1639 commit daa9f39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl

// If error:
$remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining');
if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) {
if ((429 === $response->getStatusCode()) && null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) {
$limit = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Limit');
$reset = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Reset');

Expand Down
19 changes: 19 additions & 0 deletions test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ public static function responseProvider()
),
'exception' => new \Github\Exception\RuntimeException('Field "xxxx" doesn\'t exist on type "Issue", Field "dummy" doesn\'t exist on type "PullRequest"'),
],
'Grapql requires authentication' => [
'response' => new Response(
401,
[
'content-type' => 'application/json',
'X-RateLimit-Limit' => 0,
'X-RateLimit-Remaining' => 0,
'X-RateLimit-Reset' => 1609245810,
'X-RateLimit-Used' => 0,
],
json_encode(
[
'message' => 'This endpoint requires you to be authenticated.',
'documentation_url' => 'https://docs.github.com/v3/#authentication',
]
)
),
'exception' => new \Github\Exception\RuntimeException('This endpoint requires you to be authenticated.', 401),
],
];
}
}

0 comments on commit daa9f39

Please sign in to comment.