diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index a5fa295c17684ecc0c5cdbd847a33ea947accc2b..04e38fa4109de83dcdfb89c56d2870899eb2becc 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -43,5 +43,14 @@ module Geocoder::Lookup def host "api.ipdata.co" end + + def check_response_for_errors!(response) + if response.code.to_i == 403 + raise_error(Geocoder::RequestDenied) || + Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist") + else + super(response) + end + end end end diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb index 3811a13c1a40771e961dab59139510ff0f8b1c06..5acdcf72e7b5c19fdb5ac1e57e3402fc2a4fed21 100644 --- a/test/unit/lookups/ipdata_co_test.rb +++ b/test/unit/lookups/ipdata_co_test.rb @@ -24,4 +24,12 @@ class IpdataCoTest < GeocoderTestCase assert_equal "Jersey City, NJ 07302, United States", result.address end + def test_not_authorized + Geocoder.configure(always_raise: [Geocoder::RequestDenied]) + lookup = Geocoder::Lookup.get(:ipdata_co) + assert_raises Geocoder::RequestDenied do + response = MockHttpResponse.new(code: 403) + lookup.send(:check_response_for_errors!, response) + end + end end