aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--spec/controllers/application_controller_spec.rb9
2 files changed, 9 insertions, 2 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 2cdd5ee35..1c73f06a7 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -524,7 +524,7 @@ class ApplicationController < ActionController::Base
def quietly_try_to_open(url)
begin
result = open(url).read.strip
- rescue OpenURI::HTTPError, SocketError
+ rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH
logger.warn("Unable to open third-party URL #{url}")
result = ""
end
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 1d6802940..8c3730a7e 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -2,6 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'fakeweb'
describe ApplicationController, "when accessing third party services" do
+ it "should succeed if the service responds OK" do
+ config = MySociety::Config.load_default()
+ config['GAZE_URL'] = 'http://denmark.com'
+ FakeWeb.register_uri(:get, %r|denmark.com|, :body => "DK")
+ country = self.controller.send :country_from_ip
+ country.should == "DK"
+ end
it "should fail silently if the country_from_ip domain doesn't exist" do
config = MySociety::Config.load_default()
config['GAZE_URL'] = 'http://12123sdf14qsd.com'
@@ -15,7 +22,7 @@ describe ApplicationController, "when accessing third party services" do
country.should == config['ISO_COUNTRY_CODE']
end
it "should fail silently if the country_from_ip service returns an error" do
- FakeWeb.register_uri(:get, %r|.*|, :body => "Error", :status => ["500", "Error"])
+ FakeWeb.register_uri(:get, %r|http://500.com|, :body => "Error", :status => ["500", "Error"])
config = MySociety::Config.load_default()
config['GAZE_URL'] = 'http://500.com'
country = self.controller.send :country_from_ip