diff --git a/lib/geocoder/exceptions.rb b/lib/geocoder/exceptions.rb index 208ca979e4bd91b338b774f3827be67cff3bfb9f..0ed0eb0d3954d0d2b6457655aff9f66a0c1b3250 100644 --- a/lib/geocoder/exceptions.rb +++ b/lib/geocoder/exceptions.rb @@ -8,4 +8,11 @@ module Geocoder class OverQueryLimitError < Error end + + class RequestDenied < Error + end + + class InvalidRequest < Error + end + end diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index fddf8a0d4f3dcbe5fe64c2ae530e164c18c3337c..3665e954b51dfded0e8576335bf0f4c851a10645 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -100,7 +100,8 @@ module Geocoder # Return false if exception not raised. # def raise_error(error, message = nil) - if Geocoder::Configuration.always_raise.include?( error.is_a?(Class) ? error : error.class ) + exceptions = Geocoder::Configuration.always_raise + if exceptions == :all or exceptions.include?( error.is_a?(Class) ? error : error.class ) raise error, message else false diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 21ae3cfafb35412176bc4b4951bd58169bcfd0f6..6898c267551bc056834cf7969fda1bb7fa46f4a3 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -18,9 +18,11 @@ module Geocoder::Lookup raise_error(Geocoder::OverQueryLimitError) || warn("Google Geocoding API error: over query limit.") when "REQUEST_DENIED" - warn "Google Geocoding API error: request denied." + raise_error(Geocoder::RequestDenied) || + warn("Google Geocoding API error: request denied.") when "INVALID_REQUEST" - warn "Google Geocoding API error: invalid request." + raise_error(Geocoder::InvalidRequest) || + warn("Google Geocoding API error: invalid request.") end return [] end