Skip to content
Snippets Groups Projects
Commit 884d5111 authored by Ben Woosley's avatar Ben Woosley
Browse files

Move to method-level rescue where appropriate

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