Skip to content
Snippets Groups Projects
Commit c9449a4f authored by Alex Reisner's avatar Alex Reisner
Browse files

Raise exception on Yandex API invalid key.

parent 5a641686
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,11 @@ module Geocoder::Lookup ...@@ -21,7 +21,11 @@ module Geocoder::Lookup
def results(query) def results(query)
return [] unless doc = fetch_data(query) return [] unless doc = fetch_data(query)
if err = doc['error'] if err = doc['error']
warn "Yandex Geocoding API error: #{err['status']} (#{err['message']})." if err["status"] == 401 and err["message"] == "invalid key"
raise_error(Geocoder::InvalidApiKey) || warn("Invalid API key.")
else
warn "Yandex Geocoding API error: #{err['status']} (#{err['message']})."
end
return [] return []
end end
if doc = doc['response']['GeoObjectCollection'] if doc = doc['response']['GeoObjectCollection']
......
...@@ -123,7 +123,7 @@ class ServicesTest < Test::Unit::TestCase ...@@ -123,7 +123,7 @@ class ServicesTest < Test::Unit::TestCase
# --- Yandex --- # --- Yandex ---
def test_yandex_with_invalid_key def test_yandex_warns_about_invalid_key
# keep test output clean: suppress timeout warning # keep test output clean: suppress timeout warning
orig = $VERBOSE; $VERBOSE = nil orig = $VERBOSE; $VERBOSE = nil
Geocoder.configure(:lookup => :yandex) Geocoder.configure(:lookup => :yandex)
...@@ -133,6 +133,14 @@ class ServicesTest < Test::Unit::TestCase ...@@ -133,6 +133,14 @@ class ServicesTest < Test::Unit::TestCase
$VERBOSE = orig $VERBOSE = orig
end end
def test_yandex_raises_exception_on_invalid_key
Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey])
l = Geocoder::Lookup.get(:yandex)
assert_raises Geocoder::InvalidApiKey do
l.send(:results, Geocoder::Query.new("invalid key"))
end
end
# --- Geocoder.ca --- # --- Geocoder.ca ---
......
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