如何挽救地理编码器查询限制错误?

How can I rescue geocoder query limit error?

我的模型中有以下代码

geocoded_by :street_address

在某些时候我会

place.geocode

如何确定是否达到地理编码器错误限制?我没有收到任何异常,只是打印了以下消息:Google API error: over query limit.

此外,如果地理编码不是直接触发而是通过回调触发,我该怎么做?

非常感谢!

我发现我需要生成地理编码器配置文件:

rails generate geocoder:config

并添加行:

always_raise: [Geocoder::OverQueryLimitError]

然后在我的代码中解决异常:

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

我还没有想出如何从回调中做到这一点。