mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[rubygems/rubygems] Handle connection refused and Errno::EADDRNOTAVAIL as non-retryable
cd529776d5
This commit is contained in:
parent
46a90f9998
commit
c4c646d1bb
3 changed files with 20 additions and 7 deletions
|
@ -88,8 +88,11 @@ module Bundler
|
|||
raise CertificateFailureError.new(uri)
|
||||
rescue *HTTP_ERRORS => e
|
||||
Bundler.ui.trace e
|
||||
if e.is_a?(SocketError) || e.message.to_s.include?("host down:")
|
||||
raise NetworkDownError, "Could not reach host #{uri.host}. Check your network " \
|
||||
if e.is_a?(SocketError) || e.is_a?(Errno::EADDRNOTAVAIL) || e.is_a?(Errno::ENETUNREACH) || e.is_a?(Gem::Net::HTTP::Persistent::Error)
|
||||
host = uri.host
|
||||
host_port = "#{host}:#{uri.port}"
|
||||
host = host_port if filtered_uri.to_s.include?(host_port)
|
||||
raise NetworkDownError, "Could not reach host #{host}. Check your network " \
|
||||
"connection and try again."
|
||||
else
|
||||
raise HTTPError, "Network error while fetching #{filtered_uri}" \
|
||||
|
|
|
@ -244,13 +244,23 @@ RSpec.describe Bundler::Fetcher::Downloader do
|
|||
end
|
||||
end
|
||||
|
||||
context "when error message is about no route to host" do
|
||||
context "when error is about connection refused" do
|
||||
let(:error_class) { Gem::Net::HTTP::Persistent::Error }
|
||||
let(:message) { "connection refused down: http://www.uri-to-fetch.com" }
|
||||
|
||||
it "should raise a Bundler::Fetcher::NetworkDownError" do
|
||||
expect { subject.request(uri, options) }.to raise_error(Bundler::Fetcher::NetworkDownError,
|
||||
/Could not reach host www.uri-to-fetch.com/)
|
||||
end
|
||||
end
|
||||
|
||||
context "when error is about no route to host" do
|
||||
let(:error_class) { SocketError }
|
||||
let(:message) { "Failed to open TCP connection to www.uri-to-fetch.com:443 " }
|
||||
|
||||
it "should raise a Bundler::Fetcher::HTTPError" do
|
||||
expect { subject.request(uri, options) }.to raise_error(Bundler::HTTPError,
|
||||
"Network error while fetching http://www.uri-to-fetch.com/api/v2/endpoint (#{message})")
|
||||
it "should raise a Bundler::Fetcher::NetworkDownError" do
|
||||
expect { subject.request(uri, options) }.to raise_error(Bundler::Fetcher::NetworkDownError,
|
||||
/Could not reach host www.uri-to-fetch.com/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -697,7 +697,7 @@ RSpec.describe "bundle install with gem sources" do
|
|||
end
|
||||
G
|
||||
|
||||
expect(err).to include("Could not fetch specs from http://0.0.0.0:9384/")
|
||||
expect(err).to eq("Could not reach host 0.0.0.0:9384. Check your network connection and try again.")
|
||||
expect(err).not_to include("file://")
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue