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
Branches
Tags
No related merge requests found
...@@ -106,7 +106,6 @@ module Geocoder ...@@ -106,7 +106,6 @@ 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."
...@@ -114,13 +113,11 @@ module Geocoder ...@@ -114,13 +113,11 @@ module Geocoder
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
...@@ -129,7 +126,6 @@ module Geocoder ...@@ -129,7 +126,6 @@ module Geocoder
rescue rescue
warn "Geocoding API's response was not valid JSON." warn "Geocoding API's response was not valid JSON."
end end
end
## ##
# Protocol to use for communication with geocoding services. # Protocol to use for communication with geocoding services.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment