Skip to content

Commit f91420f

Browse files
committed
bug: Fixed unexpected error with invalid api key when exception-raising is not configured
1 parent 5b379a5 commit f91420f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lib/geocoder/lookups/mapbox.rb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def results(query)
2020
sort_relevant_feature(data['features'])
2121
elsif data['message'] =~ /Invalid\sToken/
2222
raise_error(Geocoder::InvalidApiKey, data['message'])
23+
[]
2324
else
2425
[]
2526
end

test/unit/lookups/mapbox_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def test_raises_exception_with_invalid_api_key
4747
end
4848
end
4949

50+
def test_empty_array_on_invalid_api_key
51+
assert_equal [], Geocoder.search("invalid api key")
52+
end
53+
5054
def test_truncates_query_at_semicolon
5155
result = Geocoder.search("Madison Square Garden, New York, NY;123 Another St").first
5256
assert_equal [40.750755, -73.993710125], result.coordinates

0 commit comments

Comments
 (0)