diff --git a/README.md b/README.md index b41c95ff8e5debce9e2a220d1472599aea865b34..523145148c8207a5660c8fd65f63a8461b83a60c 100644 --- a/README.md +++ b/README.md @@ -1033,7 +1033,7 @@ Error Handling By default Geocoder will rescue any exceptions raised by calls to a geocoding service and return an empty array. You can override this on a per-exception basis, and also have Geocoder raise its own exceptions for certain events (eg: API quota exceeded) by using the `:always_raise` option: - Geocoder.configure(:always_raise => [SocketError, TimeoutError]) + Geocoder.configure(:always_raise => [SocketError, Timeout::Error]) You can also do this to raise all exceptions: @@ -1042,14 +1042,14 @@ You can also do this to raise all exceptions: The raise-able exceptions are: SocketError - TimeoutError + Timeout::Error Geocoder::OverQueryLimitError Geocoder::RequestDenied Geocoder::InvalidRequest Geocoder::InvalidApiKey Geocoder::ServiceUnavailable -Note that only a few of the above exceptions are raised by any given lookup, so there's no guarantee if you configure Geocoder to raise `ServiceUnavailable` that it will actually be raised under those conditions (because most APIs don't return 503 when they should; you may get a `TimeoutError` instead). Please see the source code for your particular lookup for details. +Note that only a few of the above exceptions are raised by any given lookup, so there's no guarantee if you configure Geocoder to raise `ServiceUnavailable` that it will actually be raised under those conditions (because most APIs don't return 503 when they should; you may get a `Timeout::Error` instead). Please see the source code for your particular lookup for details. Troubleshooting diff --git a/examples/reverse_geocode_job.rb b/examples/reverse_geocode_job.rb index b9954e3ebf8a5b36981bd0dc8f7f0ba9e3d4399d..a32a139c9ff412b79f6eec6b8416d8451bc3aab9 100644 --- a/examples/reverse_geocode_job.rb +++ b/examples/reverse_geocode_job.rb @@ -35,6 +35,6 @@ class ReverseGeocodeJob < ActiveJob::Base end def retryable?(exception) - exception.is_a?(TimeoutError) || exception.is_a?(SocketError) + exception.is_a?(Timeout::Error) || exception.is_a?(SocketError) end end diff --git a/lib/generators/geocoder/config/templates/initializer.rb b/lib/generators/geocoder/config/templates/initializer.rb index c8fcc4aa0b741a9418a3bf1181ec04460b8f642e..3bcc5cc372093da5bf6168be44ed216a92d1d7c0 100644 --- a/lib/generators/geocoder/config/templates/initializer.rb +++ b/lib/generators/geocoder/config/templates/initializer.rb @@ -12,7 +12,7 @@ Geocoder.configure( # Exceptions that should not be rescued by default # (if you want to implement custom error handling); - # supports SocketError and TimeoutError + # supports SocketError and Timeout::Error # always_raise: [], # Calculation options diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index 9d224b53dcff6a01b55a480e89e5e4c8ccd5eacd..1a6188729ecc2cca8befe1c91ee9d4ecf6c5ac60 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -109,7 +109,7 @@ module Geocoder # exceptions that should not be rescued by default # (if you want to implement custom error handling); - # supports SocketError and TimeoutError + # supports SocketError and Timeout::Error @data[:always_raise] = [] # calculation options diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index e8afdf88ae2e7c9b7d41d7071f066fbcf1da2ada..eb398937bab3490f9aa5f28cc93cc80df660af30 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -179,7 +179,7 @@ module Geocoder raise_error(err) or Geocoder.log(:warn, "Geocoding API connection cannot be established.") rescue Errno::ECONNREFUSED => err raise_error(err) or Geocoder.log(:warn, "Geocoding API connection refused.") - rescue TimeoutError => err + rescue Timeout::Error => err raise_error(err) or Geocoder.log(:warn, "Geocoding API not responding fast enough " + "(use Geocoder.configure(:timeout => ...) to set limit).") end diff --git a/test/test_helper.rb b/test/test_helper.rb index b869b88f81df31d6f65cf3ce8d15c63158280b2a..d6519f24076016359273307d89922c173cb98f00 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -123,7 +123,7 @@ module Geocoder remove_method(:make_api_request) def make_api_request(query) - raise TimeoutError if query.text == "timeout" + raise Timeout::Error if query.text == "timeout" raise SocketError if query.text == "socket_error" raise Errno::ECONNREFUSED if query.text == "connection_refused" if query.text == "invalid_json" diff --git a/test/unit/error_handling_test.rb b/test/unit/error_handling_test.rb index 241eaa83a2db881acf07f15c9ef21d6553c8e4e8..2052b0331e580f1cda62513060a3f3228188fadb 100644 --- a/test/unit/error_handling_test.rb +++ b/test/unit/error_handling_test.rb @@ -41,12 +41,12 @@ class ErrorHandlingTest < GeocoderTestCase end def test_always_raise_timeout_error - Geocoder.configure(:always_raise => [TimeoutError]) + Geocoder.configure(:always_raise => [Timeout::Error]) 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 TimeoutError do + assert_raises Timeout::Error do lookup.send(:results, Geocoder::Query.new("timeout")) end end