Skip to content

Commit 0724b39

Browse files
sbscullymtmail
authored andcommitted
Raise InvalidRequest is the query is not a string
1 parent 57620f5 commit 0724b39

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/opencage/geocoder.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def initialize(default_options = {})
1313
end
1414

1515
def geocode(location, options = {})
16+
raise_error("400 Not a valid location: `#{location.inspect}`") unless location.is_a?(String)
17+
1618
request = Request.new(@api_key, location, options)
1719

1820
begin

spec/open_cage/geocoder_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def geo
8383
expect(geo.geocode('NOWHERE-INTERESTING')).to eql([])
8484
end
8585

86-
it 'raises and error when undefined query', :vcr do
86+
it 'raises an error when undefined query', :vcr do
8787
expect do
8888
geo.geocode(nil)
8989
end.to raise_error(OpenCage::Error::InvalidRequest)
@@ -94,6 +94,12 @@ def geo
9494
geo.geocode('')
9595
end.to raise_error(OpenCage::Error::InvalidRequest)
9696
end
97+
98+
it 'raises a useful error when the query is not a string' do
99+
expect do
100+
geo.geocode({ query: 'NOT-A-STRING' }) # it's a hash
101+
end.to raise_error(OpenCage::Error::InvalidRequest)
102+
end
97103
end
98104

99105
describe 'user agent' do

0 commit comments

Comments
 (0)