Prevent repeated warnings when GitHub API rate limit is exceeded

This commit is contained in:
Jack Nagel 2014-02-08 16:04:53 -05:00
parent ee893fdd88
commit 7d4709d9d6
2 changed files with 5 additions and 2 deletions

View File

@ -112,7 +112,9 @@ module Homebrew extend self
end
end
results
rescue GitHub::Error
rescue GitHub::RateLimitExceededError => e
[]
rescue GitHub::Error => e
opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
[]
end

View File

@ -252,6 +252,7 @@ module GitHub extend self
ISSUES_URI = URI.parse("https://api.github.com/legacy/issues/search/Homebrew/homebrew/open/")
Error = Class.new(StandardError)
RateLimitExceededError = Class.new(Error)
def open url, headers={}, &block
# This is a no-op if the user is opting out of using the GitHub API.
@ -266,7 +267,7 @@ module GitHub extend self
end
rescue OpenURI::HTTPError => e
if e.io.meta['x-ratelimit-remaining'].to_i <= 0
raise Error, <<-EOS.undent, e.backtrace
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
and then set HOMEBREW_GITHUB_API_TOKEN.