Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when MapBox auth key is invalid #1657

Open
maxolasersquad opened this issue Jun 12, 2024 · 1 comment
Open

Error when MapBox auth key is invalid #1657

maxolasersquad opened this issue Jun 12, 2024 · 1 comment
Labels

Comments

@maxolasersquad
Copy link

maxolasersquad commented Jun 12, 2024

Expected behavior

No error should be thrown.

Actual behavior

The following error is produced:

/usr/local/bundle/gems/geocoder-1.8.3/lib/geocoder/lookups/base.rb:46:in `search': undefined method `map' for false:FalseClass (NoMethodError)

        results(query).map{ |r|
                      ^^^^
Did you mean?  tap

Steps to reproduce

Set up a Ruby on Rails application with Geocoder and configure it for MapBox, but with an invalid auth token. Try to save an Address model that uses Geocoder.

irb(main):001:0> a = Address.find 47
  Address Load (0.6ms)  SELECT "addresses".* FROM "addresses" WHERE "addresses"."id" = $1 LIMIT $2  [["id", 47], ["LIMIT", 1]]
=> 
#<Address:0x0000741c81b8f2b0
...
> a.save
  TRANSACTION (0.2ms)  BEGIN
Dalli::Server#connect 170.23.0.7:11211
Geocoding API error: 401 Unauthorized
  TRANSACTION (0.3ms)  ROLLBACK
/usr/local/bundle/gems/geocoder-1.8.3/lib/geocoder/lookups/base.rb:46:in `search': undefined method `map' for false:FalseClass (NoMethodError)

        results(query).map{ |r|
                      ^^^^
Did you mean?  tap

Environment info

  • Geocoder version: 1.8.3
  • Rails version: 7.0.8
  • Database (if applicable): Postgres
  • Lookup (if applicable): MapBox

More information

Geocoder configuration.

Geocoder.configure(
  lookup: :mapbox,
  use_https: true,
  api_key: ENV['MAPBOX'],
  units: :mi,
)
@alexreisner
Copy link
Owner

Thanks for this. I agree that it should be handled more gracefully. A Geocoder::InvalidApiKey exception should be raised (if exception-raising is configured) or an empty array should be returned. Looks like the test that checks this isn't written properly. I'm open to a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants