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

Merge pull request #214 from Empact/method-rescue

Move to method-level rescue where appropriate
parents cfdca9d0 f804322d
No related branches found
No related tags found
No related merge requests found
......@@ -106,29 +106,25 @@ module Geocoder
# Returns a parsed search result (Ruby hash).
#
def fetch_data(query, reverse = false)
begin
parse_raw_data fetch_raw_data(query, reverse)
rescue SocketError => err
raise_error(err) or warn "Geocoding API connection cannot be established."
rescue TimeoutError => err
raise_error(err) or warn "Geocoding API not responding fast enough " +
"(see Geocoder::Configuration.timeout to set limit)."
end
parse_raw_data fetch_raw_data(query, reverse)
rescue SocketError => err
raise_error(err) or warn "Geocoding API connection cannot be established."
rescue TimeoutError => err
raise_error(err) or warn "Geocoding API not responding fast enough " +
"(see Geocoder::Configuration.timeout to set limit)."
end
##
# Parses a raw search result (returns hash or array).
#
def parse_raw_data(raw_data)
begin
if defined?(ActiveSupport::JSON)
ActiveSupport::JSON.decode(raw_data)
else
JSON.parse(raw_data)
end
rescue
warn "Geocoding API's response was not valid JSON."
if defined?(ActiveSupport::JSON)
ActiveSupport::JSON.decode(raw_data)
else
JSON.parse(raw_data)
end
rescue
warn "Geocoding API's response was not valid JSON."
end
##
......
......@@ -44,11 +44,9 @@ module Geocoder
end
def geocoder_initialized?
begin
included_modules.include? Geocoder::Store.const_get(geocoder_module_name)
rescue NameError
false
end
included_modules.include? Geocoder::Store.const_get(geocoder_module_name)
rescue NameError
false
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