Skip to content

Commit d6606d0

Browse files
committed
exceptions: added RateLimitExceedException
1 parent 0904dd5 commit d6606d0

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/Github/Api.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ public function decode(Http\Response $response, array $okCodes = NULL)
266266
throw new UnauthorizedException($content->message, $code, NULL, $response);
267267

268268
case Http\Response::S403_FORBIDDEN:
269+
if ($response->getHeader('X-RateLimit-Remaining') === '0') {
270+
throw new RateLimitExceedException($content->message, $code, NULL, $response);
271+
}
269272
throw new ForbiddenException($content->message, $code, NULL, $response);
270273

271274
case Http\Response::S404_NOT_FOUND:

src/Github/exceptions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ class ForbiddenException extends ApiException
9999
{}
100100

101101

102+
/**
103+
* Rate limit exceed.
104+
* @see https://developer.github.com/v3/#rate-limiting
105+
*/
106+
class RateLimitExceedException extends ForbiddenException
107+
{}
108+
109+
102110
/**
103111
* Resource not found.
104112
* @see https://developer.github.com/v3/#authentication

tests/Github/Api.decode.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ $e = Assert::exception(function() use ($api) {
5858
Assert::null($e->getPrevious());
5959

6060

61+
$e = Assert::exception(function() use ($api) {
62+
$response = new Milo\Github\Http\Response(403, ['Content-Type' => 'application/json', 'X-RateLimit-Remaining' => '0'], '{"message":"error"}');
63+
$api->decode($response);
64+
}, 'Milo\Github\RateLimitExceedException', 'error', 403);
65+
Assert::null($e->getPrevious());
66+
67+
6168
$e = Assert::exception(function() use ($api) {
6269
$response = new Milo\Github\Http\Response(404, [], '');
6370
$api->decode($response);

0 commit comments

Comments
 (0)