Resolves
https://bugzilla.redhat.com/show_bug.cgi?id=718122
---
src/app/controllers/application_controller.rb | 16 +++++++
.../controllers/provider_accounts_controller.rb | 3 +-
src/config/locales/en.yml | 3 +
.../controllers/application_controller_spec.rb | 45 ++++++++++++++++++++
4 files changed, 66 insertions(+), 1 deletions(-)
create mode 100644 src/spec/controllers/application_controller_spec.rb
diff --git a/src/app/controllers/application_controller.rb
b/src/app/controllers/application_controller.rb
index a56556d..3dbbb05 100644
--- a/src/app/controllers/application_controller.rb
+++ b/src/app/controllers/application_controller.rb
@@ -259,4 +259,20 @@ class ApplicationController < ActionController::Base
]
end
+ # Try to clean up and internationalize certain errors we get from other components
+ # Accepts a string or an Exception
+ def humanize_error(error, options={})
+ error = error.message if error.is_a?(Exception)
+ if error.match("Connection refused - connect\\(2\\)")
+ if options[:context] == :deltacloud
+ return t('deltacloud.unreachable')
+ else
+ return t('connection_refused')
+ end
+ else
+ # Nothing else matched
+ error
+ end
+ end
+
end
diff --git a/src/app/controllers/provider_accounts_controller.rb
b/src/app/controllers/provider_accounts_controller.rb
index d36717a..d7670ac 100644
--- a/src/app/controllers/provider_accounts_controller.rb
+++ b/src/app/controllers/provider_accounts_controller.rb
@@ -94,8 +94,9 @@ class ProviderAccountsController < ApplicationController
render :action => 'new' and return
end
rescue Exception => e
+ error = humanize_error(e.message, :context => :deltacloud)
flash[:error] = "#{t('provider_accounts.index.account_not_added',
:list => @provider_account.name,
- :count => 1)}: #{e.message}"
+ :count => 1)}: #{error}"
render :action => 'new' and return
end
end
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 7081dc1..a99215d 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -284,3 +284,6 @@ en:
account_private_cert: EC2 x509 private key
account_public_cert: EC2 x509 public key
uptime: Uptime
+ deltacloud:
+ unreachable: "Deltacloud is unreachable. Please verify that it is
running."
+ connection_refused: "The connection to the remote host was refused."
diff --git a/src/spec/controllers/application_controller_spec.rb
b/src/spec/controllers/application_controller_spec.rb
new file mode 100644
index 0000000..913be65
--- /dev/null
+++ b/src/spec/controllers/application_controller_spec.rb
@@ -0,0 +1,45 @@
+#
+# Copyright (C) 2011 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at
http://www.gnu.org/copyleft/gpl.html.
+
+require 'spec_helper'
+
+describe ApplicationController do
+
+ fixtures :all
+
+ before(:each) do
+ @controller = ApplicationController.new
+ end
+
+ context "humanize_error() helper" do
+ it "should return a String given an Exception" do
+ error = Exception.new('Some arbitrary error')
+ human_error = @controller.send(:humanize_error, error)
+ human_error.should == "Some arbitrary error"
+ end
+
+ it "should consider context in lookup" do
+ error = "Connection refused - connect(2)"
+ human_error = @controller.send(:humanize_error, error)
+ human_error.should == I18n.t('connection_refused')
+ human_error2 = @controller.send(:humanize_error, error, :context =>
:deltacloud)
+ human_error2.should == I18n.t('deltacloud.unreachable')
+ end
+
+ end
+end
--
1.7.6.4