diff --git a/lib/geocoder/exceptions.rb b/lib/geocoder/exceptions.rb index 01153aaf5303a81b2e9aaa5b90e65fdf85e348d9..7f6a081c2c32a9f3f74c1334c0e7e24732e1479f 100644 --- a/lib/geocoder/exceptions.rb +++ b/lib/geocoder/exceptions.rb @@ -26,4 +26,7 @@ module Geocoder class InvalidApiKey < Error end + class ServiceUnavailable < Error + end + end diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index e88495518aa9d6b62659eacdbb4d6d1d7a5aeef1..0286012383cc1b919c323a8d7bfe906862536658 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -58,15 +58,14 @@ module Geocoder::Lookup def check_response_for_errors!(response) super - puts response if response.headers['X-MS-BM-WS-INFO'] == 1 # Occasionally, the servers processing service requests can be overloaded, # and you may receive some responses that contain no results for queries that # you would normally receive a result. To identify this situation, # check the HTTP headers of the response. If the HTTP header X-MS-BM-WS-INFO is set to 1, # it is best to wait a few seconds and try again. - raise_error(Geocoder::OverQueryLimitError) || - warn("Bing Geocoding API error: Service Requests Overloaded") + raise_error(Geocoder::ServiceUnavailable) || + warn("Bing Geocoding API error: Service Unavailable") end end end diff --git a/test/fixtures/bing_over_limit b/test/fixtures/bing_service_unavailable similarity index 100% rename from test/fixtures/bing_over_limit rename to test/fixtures/bing_service_unavailable diff --git a/test/test_helper.rb b/test/test_helper.rb index 5ee0ede206179ec090f1937486669b7c6338b8fe..e00638beeb0fd9433c6d6336cc456ff54b166552 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -121,7 +121,7 @@ module Geocoder class Bing private def read_fixture(file) - if file == "bing_over_limit" + if file == "bing_service_unavailable" filepath = File.join("test", "fixtures", file) s = File.read(filepath).strip.gsub(/\n\s*/, "") MockHttpResponse.new(body: s, code: "200", headers: {'X-MS-BM-WS-INFO' => 1}) diff --git a/test/unit/lookups/bing_test.rb b/test/unit/lookups/bing_test.rb index f7c988461b786e7f87efd0b01e466eca5a6b925e..68e457925681085a532eca2c0a7b5ae3a6661df0 100644 --- a/test/unit/lookups/bing_test.rb +++ b/test/unit/lookups/bing_test.rb @@ -66,11 +66,11 @@ class BingTest < GeocoderTestCase assert_no_match(/query/, url) end - def test_raises_exception_when_service_request_overloaded - Geocoder.configure(:always_raise => [Geocoder::OverQueryLimitError]) + def test_raises_exception_when_service_unavailable + Geocoder.configure(:always_raise => [Geocoder::ServiceUnavailable]) l = Geocoder::Lookup.get(:bing) - assert_raises Geocoder::OverQueryLimitError do - l.send(:results, Geocoder::Query.new("over limit")) + assert_raises Geocoder::ServiceUnavailable do + l.send(:results, Geocoder::Query.new("service unavailable")) end end end