Skip to content

Commit 1a650c1

Browse files
glaubinixacrobat
authored andcommitted
ExceptionThrower: adjust rate limit detection
1 parent 271b3ca commit 1a650c1

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
@@ -37,7 +37,7 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla
3737

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

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

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

0 commit comments

Comments
 (0)