Skip to content

Commit 57620f5

Browse files
authored
raise 400 (bad request) error when input coordinates are undefined (#34)
1 parent 5b15109 commit 57620f5

19 files changed

+518
-373
lines changed

lib/opencage/geocoder.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ def geocode(location, options = {})
3232
end
3333

3434
def reverse_geocode(lat, lng, options = {})
35-
lat = to_float(lat)
36-
lng = to_float(lng)
35+
begin
36+
lat = to_float(lat)
37+
lng = to_float(lng)
38+
rescue TypeError
39+
raise_error("400 Not valid numeric coordinates: #{lat.inspect}, #{lng.inspect}")
40+
end
3741

3842
if [lat, lng].any? { |coord| !coord.is_a?(Numeric) }
3943
raise_error("400 Not valid numeric coordinates: #{lat.inspect}, #{lng.inspect}")

spec/cassettes/OpenCage_Geocoder/_geocode/correctly_parses_a_request_with_encoding_in_the_response.yml

Lines changed: 27 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/OpenCage_Geocoder/_geocode/empty_list_when_no_results_are_found.yml

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)