mapbox / mapbox-sdk-rb

A Ruby interface to Mapbox APIs.
Other
59 stars 32 forks source link

API Error Parsing #53

Open volleio opened 3 years ago

volleio commented 3 years ago

This is a fix for #42 Error Granularity. Exceptions raised by the API will be returned with the correct message provided by the Mapbox API, such as: API Error: 422 Unprocessable Entity - Query too long - 273/256 characters

fix: correct api error message parsing fix: raise exceptions with formatted string

samfader commented 3 years ago

@volleio This looks good. Do you have any examples of queries that this helps? i.e. a sample query that fails and that your code gives some more context to?

danielmorrison commented 2 years ago

I can provide one. Here's the error I get from the gem:

StandardError: Invalid response object from API: <RestClient::Response 403 "{\"message\":..."> (HTTP response code was 403 Forbidden)

After this, I get the full message with an actionable step:

/Users/daniel/.rvm/gems/ruby-3.1.2/bundler/gems/mapbox-sdk-rb-46479c8ca614/lib/mapbox.rb:120:in `handle_api_error': API Error: 403 Forbidden - Permanent geocodes are not enabled for this account. Contact sales@mapbox.com to enable this feature. (StandardError)

danielmorrison commented 10 months ago

I hit this again today on another app. Fortunately I remembered my comment above, so I know to go request access to the Permanent Geocode API.

Would love to see this get merged.

samfader commented 10 months ago

Hi, unfortunately I'm not sure anyone maintains this library at this point @danielmorrison. Are you open to reviewing and merging? I can give you access to publishing the gem on RubyGems as well if desired.

danielmorrison commented 10 months ago

@samfader shoot but yeah I'd be open to that. I'm danielmorrison on RubyGems.

samfader commented 10 months ago

@danielmorrison Added! Let me know if that works.

danielmorrison commented 10 months ago

@samfader RubyGems works. Can you give me write access here too?

samfader commented 10 months ago

Ah unfortunately I don't have write access and honestly not sure who does anymore :( Are you in contact with anyone at Mapbox? Might be worth reaching out to them.