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
20 changes: 18 additions & 2 deletions lib/Github/Exception/ApiLimitExceedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,24 @@
*/
class ApiLimitExceedException extends RuntimeException
{
public function __construct($limit = 5000, $code = 0, $previous = null)
private $limit;
private $reset;

public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add the new argument in the middle. It requires everyone using the exception themselves to update their code.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but we are soon about to tag 2.0.0. So it is okey to break BC here.

Though, it should be documented in the change log of the next release.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this going to be only part of a new major release, this change is fine of course.

{
$this->limit = (int) $limit;
$this->reset = (int) $reset;

parent::__construct(sprintf('You have reached GitHub hourly limit! Actual limit is: %d', $limit), $code, $previous);
}

public function getLimit()
{
return $this->limit;
}

public function getResetTime()
{
parent::__construct('You have reached GitHub hour limit! Actual limit is: '. $limit, $code, $previous);
return $this->reset;
}
}
7 changes: 4 additions & 3 deletions lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public function handleRequest(RequestInterface $request, callable $next, callabl

// If error:
$remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining');
$limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit');

if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) {
throw new ApiLimitExceedException($limit);
$limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit');
$reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset');

throw new ApiLimitExceedException($limit, $reset);
}

if (401 === $response->getStatusCode()) {
Expand Down