From ef62bde0eee8828f699856c2e07d991cc502a20f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 6 Nov 2012 15:21:36 -0500 Subject: [PATCH] Improve Yahoo error handling. Add test and display Yahoo's error message in warning. --- lib/geocoder/lookups/yahoo.rb | 2 +- test/fixtures/yahoo_error.json | 1 + test/services_test.rb | 8 ++++++++ test/test_helper.rb | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/yahoo_error.json diff --git a/lib/geocoder/lookups/yahoo.rb b/lib/geocoder/lookups/yahoo.rb index adbe2e98..b4cd2dbd 100644 --- a/lib/geocoder/lookups/yahoo.rb +++ b/lib/geocoder/lookups/yahoo.rb @@ -21,7 +21,7 @@ module Geocoder::Lookup return [] end else - warn "Yahoo Geocoding API error: #{doc['responsecode']}." + warn "Yahoo Geocoding API error: #{doc['responsecode']} (#{doc['reason']})." return [] end end diff --git a/test/fixtures/yahoo_error.json b/test/fixtures/yahoo_error.json new file mode 100644 index 00000000..7dbfdfea --- /dev/null +++ b/test/fixtures/yahoo_error.json @@ -0,0 +1 @@ +{"bossresponse":{"responsecode":"6000","reason":"internal error"}} diff --git a/test/services_test.rb b/test/services_test.rb index 9d204aac..19898d69 100644 --- a/test/services_test.rb +++ b/test/services_test.rb @@ -82,6 +82,14 @@ class ServicesTest < Test::Unit::TestCase assert_equal [], Geocoder.search("no results") end + def test_yahoo_error + Geocoder::Configuration.lookup = :yahoo + # keep test output clean: suppress timeout warning + orig = $VERBOSE; $VERBOSE = nil + assert_equal [], Geocoder.search("error") + $VERBOSE = orig + end + def test_yahoo_result_components Geocoder::Configuration.lookup = :yahoo result = Geocoder.search("madison square garden").first diff --git a/test/test_helper.rb b/test/test_helper.rb index 7361b300..8285233e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -104,6 +104,7 @@ module Geocoder raise SocketError if query.text == "socket_error" file = case query.text when "no results"; :no_results + when "error"; :error else :madison_square_garden end read_fixture "yahoo_#{file}.json" -- GitLab