mirror of
https://github.com/lostisland/faraday.git
synced 2025-08-10 00:03:15 -04:00
ensure consistent handling of connection failures
All adapters should now raise Faraday::Error::ConnectionFailed
This commit is contained in:
parent
715e1af7d1
commit
f28bf056cf
@ -18,6 +18,8 @@ module Faraday
|
||||
rescue Net::HTTP::Persistent::Error => error
|
||||
if error.message.include? 'Timeout'
|
||||
raise Faraday::Error::TimeoutError, error
|
||||
elsif error.message.include? 'connection refused'
|
||||
raise Faraday::Error::ConnectionFailed, error
|
||||
else
|
||||
raise
|
||||
end
|
||||
|
@ -31,7 +31,7 @@ module Faraday
|
||||
response = begin
|
||||
data = env[:body] ? env[:body].to_s : nil
|
||||
session.request(env[:method], env[:url].to_s, env[:request_headers], :data => data)
|
||||
rescue Errno::ECONNREFUSED
|
||||
rescue Errno::ECONNREFUSED, ::Patron::ConnectionFailed
|
||||
raise Error::ConnectionFailed, $!
|
||||
end
|
||||
|
||||
|
@ -56,6 +56,15 @@ module Faraday
|
||||
end
|
||||
end
|
||||
|
||||
case resp.curl_return_code
|
||||
when 0
|
||||
# everything OK
|
||||
when 7
|
||||
raise Error::ConnectionFailed, resp.curl_error_message
|
||||
else
|
||||
raise Error::ClientError, resp.curl_error_message
|
||||
end
|
||||
|
||||
save_response(env, resp.code, resp.body) do |response_headers|
|
||||
response_headers.parse resp.headers
|
||||
end
|
||||
|
@ -166,6 +166,12 @@ module Adapters
|
||||
end
|
||||
end
|
||||
|
||||
def test_connection_error
|
||||
assert_raises Faraday::Error::ConnectionFailed do
|
||||
get 'http://localhost:4'
|
||||
end
|
||||
end
|
||||
|
||||
def test_empty_body_response_represented_as_blank_string
|
||||
response = get('204')
|
||||
assert_equal '', response.body
|
||||
|
@ -22,5 +22,8 @@ module Adapters
|
||||
rescue Faraday::Error::ClientError
|
||||
end
|
||||
end
|
||||
|
||||
# test not applicable
|
||||
undef test_connection_error
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user