Skip to content

Commit

Permalink
Make SmartyStreets recognize errors.
Browse files Browse the repository at this point in the history
Fixes #1426.
  • Loading branch information
alexreisner committed Mar 17, 2020
1 parent 8956162 commit 5a4bee2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/geocoder/lookups/smarty_streets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def query_url_params(query)
end

def results(query)
fetch_data(query) || []
doc = fetch_data(query) || []
if doc.is_a?(Hash) and doc.key?('status') # implies there's an error
return []
else
return doc
end
end
end
end
1 change: 1 addition & 0 deletions test/fixtures/smarty_streets_10300
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"input_index":0, "status":"invalid_zipcode", "reason":"Invalid ZIP Code."}
6 changes: 6 additions & 0 deletions test/unit/lookups/smarty_streets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def test_no_results
assert_equal 0, results.length
end

def test_invalid_zipcode_returns_no_results
assert_nothing_raised do
assert_nil Geocoder.search("10300").first
end
end

def test_raises_exception_on_error_http_status
error_statuses = {
'400' => Geocoder::InvalidRequest,
Expand Down

0 comments on commit 5a4bee2

Please sign in to comment.