Skip to content
Snippets Groups Projects
Commit 7511dc9a authored by Alex Reisner's avatar Alex Reisner
Browse files

Rescue from Errno::ECONNREFUSED.

Response to GH issues #579 and #663.
parent 2e98af6c
No related branches found
No related tags found
No related merge requests found
...@@ -169,6 +169,8 @@ module Geocoder ...@@ -169,6 +169,8 @@ module Geocoder
parse_raw_data fetch_raw_data(query) parse_raw_data fetch_raw_data(query)
rescue SocketError => err rescue SocketError => err
raise_error(err) or warn "Geocoding API connection cannot be established." raise_error(err) or warn "Geocoding API connection cannot be established."
rescue Errno::ECONNREFUSED => err
raise_error(err) or warn "Geocoding API connection refused."
rescue TimeoutError => err rescue TimeoutError => err
raise_error(err) or warn "Geocoding API not responding fast enough " + raise_error(err) or warn "Geocoding API not responding fast enough " +
"(use Geocoder.configure(:timeout => ...) to set limit)." "(use Geocoder.configure(:timeout => ...) to set limit)."
......
...@@ -110,6 +110,7 @@ module Geocoder ...@@ -110,6 +110,7 @@ module Geocoder
def make_api_request(query) def make_api_request(query)
raise TimeoutError if query.text == "timeout" raise TimeoutError if query.text == "timeout"
raise SocketError if query.text == "socket_error" raise SocketError if query.text == "socket_error"
raise Errno::ECONNREFUSED if query.text == "connection_refused"
read_fixture fixture_for_query(query) read_fixture fixture_for_query(query)
end end
end end
......
...@@ -41,4 +41,16 @@ class ErrorHandlingTest < GeocoderTestCase ...@@ -41,4 +41,16 @@ class ErrorHandlingTest < GeocoderTestCase
end end
end end
end end
def test_always_raise_connection_refused_error
Geocoder.configure(:always_raise => [Errno::ECONNREFUSED])
Geocoder::Lookup.all_services_except_test.each do |l|
next if l == :maxmind_local # local, does not raise timeout
lookup = Geocoder::Lookup.get(l)
set_api_key!(l)
assert_raises Errno::ECONNREFUSED do
lookup.send(:results, Geocoder::Query.new("connection_refused"))
end
end
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment