Skip to content

Commit 5a4bee2

Browse files
committed
Make SmartyStreets recognize errors.
Fixes #1426.
1 parent 8956162 commit 5a4bee2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/geocoder/lookups/smarty_streets.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def query_url_params(query)
5757
end
5858

5959
def results(query)
60-
fetch_data(query) || []
60+
doc = fetch_data(query) || []
61+
if doc.is_a?(Hash) and doc.key?('status') # implies there's an error
62+
return []
63+
else
64+
return doc
65+
end
6166
end
6267
end
6368
end

test/fixtures/smarty_streets_10300

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"input_index":0, "status":"invalid_zipcode", "reason":"Invalid ZIP Code."}

test/unit/lookups/smarty_streets_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def test_no_results
7373
assert_equal 0, results.length
7474
end
7575

76+
def test_invalid_zipcode_returns_no_results
77+
assert_nothing_raised do
78+
assert_nil Geocoder.search("10300").first
79+
end
80+
end
81+
7682
def test_raises_exception_on_error_http_status
7783
error_statuses = {
7884
'400' => Geocoder::InvalidRequest,

0 commit comments

Comments
 (0)