Skip to content

Commit 11f2bd9

Browse files
committed
Add error handling case for HTTP 405
1 parent b2c0aa5 commit 11f2bd9

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/geocoder/exceptions.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ class LookupTimeout < ::Timeout::Error
3737
class NetworkError < Error
3838
end
3939

40+
class MethodNotAllowed < Error
41+
end
42+
4043
end

lib/geocoder/lookups/base.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ def check_response_for_errors!(response)
281281
elsif response.code.to_i == 402
282282
raise_error(Geocoder::OverQueryLimitError) ||
283283
Geocoder.log(:warn, "Geocoding API error: 402 Payment Required")
284+
elsif response.code.to_i == 405
285+
raise_error(Geocoder::MethodNotAllowed) ||
286+
Geocoder.log(:warn, "Geocoding API error: 405 Method Not Allowed")
284287
elsif response.code.to_i == 429
285288
raise_error(Geocoder::OverQueryLimitError) ||
286289
Geocoder.log(:warn, "Geocoding API error: 429 Too Many Requests")

test/unit/lookups/nominatim_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,13 @@ def test_raises_exception_when_over_query_limit
4848
l.send(:results, Geocoder::Query.new("over limit"))
4949
end
5050
end
51+
52+
def test_raises_exception_when_method_not_allowed
53+
Geocoder.configure(:always_raise => [Geocoder::MethodNotAllowed])
54+
l = Geocoder::Lookup.get(:nominatim)
55+
assert_raises Geocoder::MethodNotAllowed do
56+
response = MockHttpResponse.new(code: 405)
57+
l.send(:check_response_for_errors!, response)
58+
end
59+
end
5160
end

0 commit comments

Comments
 (0)