Add a more useful message when ratelimit is exceeded
This commit is contained in:
parent
f7cda3cdb6
commit
24cbb4fd2e
@ -280,10 +280,13 @@ module GitHub extend self
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle_api_error(e)
|
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
|
raise RateLimitExceededError, <<-EOS.undent, e.backtrace
|
||||||
GitHub #{Utils::JSON.load(e.io.read)['message']}
|
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.
|
and then set HOMEBREW_GITHUB_API_TOKEN.
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
@ -298,6 +301,14 @@ module GitHub extend self
|
|||||||
end
|
end
|
||||||
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={})
|
def issues_matching(query, qualifiers={})
|
||||||
uri = ISSUES_URI.dup
|
uri = ISSUES_URI.dup
|
||||||
uri.query = build_query_string(query, qualifiers)
|
uri.query = build_query_string(query, qualifiers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user