Skip to content
Snippets Groups Projects
Commit e0cc8e7d authored by Alex Reisner's avatar Alex Reisner
Browse files

Issue warning on Google API connection problems.

parent 8edcaa3b
No related branches found
No related tags found
No related merge requests found
......@@ -47,13 +47,19 @@ module Geocoder
# Returns nil if non-200 HTTP response, timeout, or other error.
#
def parsed_response(query, reverse = false)
if doc = fetch_data(query, reverse)
doc = ActiveSupport::JSON.decode(doc)
if doc && doc['status'] == "OK"
return doc
elsif doc['status'] == "OVER_QUERY_LIMIT"
warn "Google Geocoder API error: quota exceeded."
begin
doc = ActiveSupport::JSON.decode(fetch_data(query, reverse))
rescue SocketError
warn "Google Geocoder API connection cannot be established."
rescue TimeoutError
warn "Google Geocoder API not responding fast enough " +
"(see Geocoder::Configuration.timeout to set limit)."
end
case doc['status']; when "OK"
doc
when "OVER_QUERY_LIMIT"
warn "Google Geocoder API error: quota exceeded."
end
end
......@@ -63,14 +69,9 @@ module Geocoder
def fetch_data(query, reverse = false)
return nil if query.blank?
url = query_url(query, reverse)
begin
resp = nil
timeout(Geocoder::Configuration.timeout) do
Net::HTTP.get_response(URI.parse(url)).body
end
rescue SocketError, TimeoutError
return nil
end
end
def query_url(query, reverse = false)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment