Skip to content

Commit dc31352

Browse files
committed
Raise InvalidRequest is the query is not a string
1 parent 5b15109 commit dc31352

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ def geo
8282
it 'empty list when no results are found', :vcr do
8383
expect(geo.geocode('NOWHERE-INTERESTING')).to eql([])
8484
end
85+
86+
it 'throws a useful error when the query is not a string' do
87+
expect do
88+
geo.geocode({ query: 'NOT-A-STRING' })
89+
end.to raise_error(OpenCage::Error::InvalidRequest)
90+
end
8591
end
8692

8793
describe 'user agent' do

0 commit comments

Comments
 (0)