Skip to content
Snippets Groups Projects
Commit 24cbb4fd authored by Jack Nagel's avatar Jack Nagel
Browse files

Add a more useful message when ratelimit is exceeded

parent f7cda3cd
No related branches found
No related tags found
No related merge requests found
......@@ -280,10 +280,13 @@ module GitHub extend self
end
def handle_api_error(e)
if e.io.meta['x-ratelimit-remaining'].to_i <= 0
if e.io.meta["x-ratelimit-remaining"].to_i <= 0
reset = e.io.meta.fetch("x-ratelimit-reset").to_i
raise RateLimitExceededError, <<-EOS.undent, e.backtrace
GitHub #{Utils::JSON.load(e.io.read)['message']}
You may want to create an API token: https://github.com/settings/applications
Try again in #{pretty_ratelimit_reset(reset)}, or create an API token:
https://github.com/settings/applications
and then set HOMEBREW_GITHUB_API_TOKEN.
EOS
end
......@@ -298,6 +301,14 @@ module GitHub extend self
end
end
def pretty_ratelimit_reset(reset)
if (seconds = Time.at(reset) - Time.now) > 180
"%d minutes %d seconds" % [seconds / 60, seconds % 60]
else
"#{seconds} seconds"
end
end
def issues_matching(query, qualifiers={})
uri = ISSUES_URI.dup
uri.query = build_query_string(query, qualifiers)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment