aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/fetcher
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-01-04 22:07:00 -0600
committerSamuel Giddins <segiddins@segiddins.me>2016-01-25 10:49:51 -0600
commit7e8a350c6c50944d6ffd88466c4546e3fca6c5d8 (patch)
treea35c7e0e1493907122797bd4b797eec5a4d1ef9d /lib/bundler/fetcher
parent18a27b3ad92ee4b7d96bc3c27028b6752d682ec5 (diff)
downloadbundler-7e8a350c6c50944d6ffd88466c4546e3fca6c5d8.tar.gz
[CompactIndex] Centralize error handling
Diffstat (limited to 'lib/bundler/fetcher')
-rw-r--r--lib/bundler/fetcher/compact_index.rb34
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb
index 78178f60..fcd5e512 100644
--- a/lib/bundler/fetcher/compact_index.rb
+++ b/lib/bundler/fetcher/compact_index.rb
@@ -6,16 +6,27 @@ module Bundler
class CompactIndex < Base
require "bundler/vendor/compact_index_client/lib/compact_index_client"
+ def self.compact_index_request(method_name)
+ method = instance_method(method_name)
+ define_method(method_name) do |*args, &blk|
+ begin
+ method.bind(self).call(*args, &blk)
+ rescue NetworkDownError, CompactIndexClient::Updater::MisMatchedChecksumError => e
+ raise HTTPError, e.message
+ rescue AuthenticationRequiredError
+ # We got a 401 from the server. Just fail.
+ raise
+ rescue HTTPError => e
+ Bundler.ui.trace(e)
+ nil
+ end
+ end
+ end
+
def specs(gem_names)
specs_for_names(gem_names)
- rescue NetworkDownError, CompactIndexClient::Updater::MisMatchedChecksumError => e
- raise HTTPError, e.message
- rescue AuthenticationRequiredError
- raise # We got a 401 from the server. Just fail.
- rescue HTTPError => e
- Bundler.ui.trace(e)
- nil
end
+ compact_index_request :specs
def specs_for_names(gem_names)
gem_info = []
@@ -43,18 +54,13 @@ module Bundler
contents[3].map! {|d| Gem::Dependency.new(*d) }
EndpointSpecification.new(*contents)
end
+ compact_index_request :fetch_spec
def available?
# Read info file checksums out of /versions, so we can know if gems are up to date
fetch_uri.scheme != "file" && compact_index_client.update_and_parse_checksums!
- rescue NetworkDownError, CompactIndexClient::Updater::MisMatchedChecksumError => e
- raise HTTPError, e.message
- rescue AuthenticationRequiredError
- # We got a 401 from the server. Just fail.
- raise
- rescue HTTPError
- false
end
+ compact_index_request :available?
def api_fetcher?
true