Skip to content
Snippets Groups Projects
Commit 7f3cb08c authored by Dan Drinkard's avatar Dan Drinkard
Browse files

Raise on 400, 402

parent d807048c
No related branches found
No related tags found
No related merge requests found
......@@ -225,9 +225,15 @@ module Geocoder
end
def check_response_for_errors!(response)
if response.code.to_i == 401
if response.code.to_i == 400
raise_error(Geocoder::InvalidRequest) ||
warn("Geocoding API error: 400 Invalid Request")
elsif response.code.to_i == 401
raise_error(Geocoder::RequestDenied) ||
warn("Geocoding API error: 401 Unauthorized")
elsif response.code.to_i == 402
raise_error(Geocoder::OverQueryLimitError) ||
warn("Geocoding API error: 402 Forbidden")
end
end
......
......@@ -56,7 +56,32 @@ class LookupTest < GeocoderTestCase
end
end
def test_raises_exception_on_401_response
def test_raises_exception_on_error_http_status
error_statuses = {
'400' => Geocoder::InvalidRequest,
'401' => Geocoder::RequestDenied,
'402' => Geocoder::OverQueryLimitError
}
Geocoder.configure(always_raise: error_statuses.values)
error_statuses.each do |code, err|
assert_raises err do
lookup = Geocoder::Lookup.get(:smarty_streets)
response = MockHttpResponse.new(code: code.to_i)
lookup.send(:check_response_for_errors!, response)
end
end
end
def test_raises_exception_on_401_response
Geocoder.configure(always_raise: [Geocoder::RequestDenied])
assert_raises Geocoder::RequestDenied do
lookup = Geocoder::Lookup.get(:smarty_streets)
response = MockHttpResponse.new(code: 401)
lookup.send(:check_response_for_errors!, response)
end
end
def test_raises_exception_on_402_response
Geocoder.configure(always_raise: [Geocoder::RequestDenied])
assert_raises Geocoder::RequestDenied do
lookup = Geocoder::Lookup.get(:smarty_streets)
......
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