ruby-on-railsgoogle-geocoderrails-geocoder

How can I rescue geocoder query limit error?


I have the following code in my model

geocoded_by :street_address

And in some point I do

place.geocode

How can I identify if the geocoder error limit is reached? I'm not getting any exception, just the following message is printed: Google API error: over query limit.

Also, how do I do this if the geocode is triggered not directly but by a callback?

Thank you very much!


Solution

  • I figured out I needed to generate the geocoder config file with:

    rails generate geocoder:config

    and add the line:

    always_raise: [Geocoder::OverQueryLimitError].

    Then in my code rescue the exception:

    def my_method
      place.geocode
    rescue Geocoder::OverQueryLimitError
      puts('The geocoder limit has been reached.')
    end
    

    I haven't figured out yet how to do it from a callback.