aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorJack Nagel2014-02-16 22:24:33 -0500
committerJack Nagel2014-02-16 22:24:33 -0500
commit1d5ab3195cb9c19a349ccdcdf6c4f75d7c02460b (patch)
tree8b9ec8c3eaab244cb8c670ed82898d033a58297f /Library/Homebrew
parent34930586c342dcf10e36ab3eb0c5388dff708e5f (diff)
downloadbrew-1d5ab3195cb9c19a349ccdcdf6c4f75d7c02460b.tar.bz2
Extract error handling from GitHub.open
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/utils.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 6d13d0583..c6fe46a5e 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -271,21 +271,28 @@ module GitHub extend self
yield Utils::JSON.load(f.read)
end
rescue OpenURI::HTTPError => e
+ handle_api_error(e)
+ rescue SocketError, OpenSSL::SSL::SSLError => e
+ raise Error, "Failed to connect to: #{url}\n#{e.message}", e.backtrace
+ rescue Utils::JSON::Error => e
+ raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace
+ end
+
+ def handle_api_error(e)
if e.io.meta['x-ratelimit-remaining'].to_i <= 0
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.
EOS
- elsif e.io.status.first == "404"
+ end
+
+ case e.io.status.first
+ when "404"
raise HTTPNotFoundError, e.message, e.backtrace
else
raise Error, e.message, e.backtrace
end
- rescue SocketError, OpenSSL::SSL::SSLError => e
- raise Error, "Failed to connect to: #{url}\n#{e.message}", e.backtrace
- rescue Utils::JSON::Error => e
- raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace
end
def issues_matching(query, qualifiers={})