diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2012-01-17 11:30:56 +0000 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2012-01-17 11:30:56 +0000 |
commit | 3b0222d887e2ef1bd508e505b2327f8c2acac1d3 (patch) | |
tree | 1c135dbf1c311c8c729fdb6bc9882d9cd35f4fc1 /app/controllers/application_controller.rb | |
parent | a714a0b2761f0c88665eee3088fd3127e0bb5e05 (diff) |
Fail silently if third party services are broken or unavailable. Fixes #354.
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2633aca4d..f6068120d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -504,12 +504,22 @@ class ApplicationController < ActionController::Base default = MySociety::Config.get('ISO_COUNTRY_CODE', '') country = "" if !gaze.empty? - country = open("#{gaze}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}").read.strip + country = quietly_try_to_open("#{gaze}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}") end country = default if country.empty? return country end + def quietly_try_to_open(url) + begin + result = open(url).read.strip + rescue OpenURI::HTTPError, SocketError + logger.warn("Unable to open third-party URL #{url}") + result = "" + end + return result + end + # URL generating functions are needed by all controllers (for redirects), # views (for links) and mailers (for use in emails), so include them into # all of all. |