Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla

// 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 @@ -177,6 +177,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),
],
];
}
}