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 ...@@ -47,13 +47,19 @@ module Geocoder
# Returns nil if non-200 HTTP response, timeout, or other error. # Returns nil if non-200 HTTP response, timeout, or other error.
# #
def parsed_response(query, reverse = false) def parsed_response(query, reverse = false)
if doc = fetch_data(query, reverse) begin
doc = ActiveSupport::JSON.decode(doc) doc = ActiveSupport::JSON.decode(fetch_data(query, reverse))
if doc && doc['status'] == "OK" rescue SocketError
return doc warn "Google Geocoder API connection cannot be established."
elsif doc['status'] == "OVER_QUERY_LIMIT" rescue TimeoutError
warn "Google Geocoder API error: quota exceeded." warn "Google Geocoder API not responding fast enough " +
end "(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
end end
...@@ -63,13 +69,8 @@ module Geocoder ...@@ -63,13 +69,8 @@ module Geocoder
def fetch_data(query, reverse = false) def fetch_data(query, reverse = false)
return nil if query.blank? return nil if query.blank?
url = query_url(query, reverse) url = query_url(query, reverse)
begin timeout(Geocoder::Configuration.timeout) do
resp = nil Net::HTTP.get_response(URI.parse(url)).body
timeout(Geocoder::Configuration.timeout) do
Net::HTTP.get_response(URI.parse(url)).body
end
rescue SocketError, TimeoutError
return nil
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment