Skip to content
Snippets Groups Projects
Commit e775f167 authored by Hassanin Ahmed's avatar Hassanin Ahmed Committed by Thu Trang Pham
Browse files

handles unreachable network exception (#1030)

* handles unreachable network exception

* adds network error class

* tests unreachable host exception handling
parent 77fb2e47
No related branches found
No related tags found
No related merge requests found
......@@ -34,4 +34,7 @@ module Geocoder
class LookupTimeout < ::Timeout::Error
end
class NetworkError < Error
end
end
......@@ -286,6 +286,8 @@ module Geocoder
end
rescue Timeout::Error
raise Geocoder::LookupTimeout
rescue Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Errno::ENETUNREACH
raise Geocoder::NetworkError
end
def use_ssl?
......
......@@ -129,6 +129,7 @@ module Geocoder
raise Timeout::Error if query.text == "timeout"
raise SocketError if query.text == "socket_error"
raise Errno::ECONNREFUSED if query.text == "connection_refused"
raise Errno::EHOSTUNREACH if query.text == "host_unreachable"
if query.text == "invalid_json"
return MockHttpResponse.new(:body => 'invalid json', :code => 200)
end
......
......@@ -75,4 +75,16 @@ class ErrorHandlingTest < GeocoderTestCase
end
end
end
def test_always_raise_host_unreachable_error
Geocoder.configure(:always_raise => [Errno::EHOSTUNREACH])
Geocoder::Lookup.all_services_except_test.each do |l|
next if l == :maxmind_local || l == :geoip2 # local, does not use cache
lookup = Geocoder::Lookup.get(l)
set_api_key!(l)
assert_raises Errno::EHOSTUNREACH do
lookup.send(:results, Geocoder::Query.new("host_unreachable"))
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