aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/utils.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index ab186eedd..6684b3696 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -311,15 +311,18 @@ module GitHub extend self
}
default_headers['Authorization'] = "token #{HOMEBREW_GITHUB_API_TOKEN}" if HOMEBREW_GITHUB_API_TOKEN
- Kernel.open(url, default_headers.merge(headers)) do |f|
- yield Utils::JSON.load(f.read)
+
+ begin
+ Kernel.open(url, default_headers.merge(headers)) do |f|
+ 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
- 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)