Skip to content

Commit daa9f39

Browse files
committed
Merge branch '2.x'
* 2.x: ExceptionThrower: adjust rate limit detection
2 parents 0e09516 + 89f1639 commit daa9f39

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/Github/HttpClient/Plugin/GithubExceptionThrower.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
3434

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

test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ public static function responseProvider()
181181
),
182182
'exception' => new \Github\Exception\RuntimeException('Field "xxxx" doesn\'t exist on type "Issue", Field "dummy" doesn\'t exist on type "PullRequest"'),
183183
],
184+
'Grapql requires authentication' => [
185+
'response' => new Response(
186+
401,
187+
[
188+
'content-type' => 'application/json',
189+
'X-RateLimit-Limit' => 0,
190+
'X-RateLimit-Remaining' => 0,
191+
'X-RateLimit-Reset' => 1609245810,
192+
'X-RateLimit-Used' => 0,
193+
],
194+
json_encode(
195+
[
196+
'message' => 'This endpoint requires you to be authenticated.',
197+
'documentation_url' => 'https://docs.github.com/v3/#authentication',
198+
]
199+
)
200+
),
201+
'exception' => new \Github\Exception\RuntimeException('This endpoint requires you to be authenticated.', 401),
202+
],
184203
];
185204
}
186205
}

0 commit comments

Comments
 (0)