Resolves
https://bugzilla.redhat.com/show_bug.cgi?id=718122
---
.../controllers/provider_accounts_controller.rb | 3 ++-
src/app/helpers/application_helper.rb | 16 ++++++++++++++++
src/config/locales/en.yml | 3 +++
src/spec/helpers/application_helper_spec.rb | 14 ++++++++++++++
4 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/src/app/controllers/provider_accounts_controller.rb
b/src/app/controllers/provider_accounts_controller.rb
index b3f6394..2a8a930 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/app/helpers/application_helper.rb
b/src/app/helpers/application_helper.rb
index 0135722..0902466 100644
--- a/src/app/helpers/application_helper.rb
+++ b/src/app/helpers/application_helper.rb
@@ -150,5 +150,21 @@ module ApplicationHelper
session[:javascript_enabled]
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
+
module_function :count_uptime
end
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 6c87532..7431587 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -278,3 +278,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/helpers/application_helper_spec.rb
b/src/spec/helpers/application_helper_spec.rb
index 98388aa..abfd13b 100644
--- a/src/spec/helpers/application_helper_spec.rb
+++ b/src/spec/helpers/application_helper_spec.rb
@@ -60,4 +60,18 @@ describe ApplicationHelper do
end
+ context "humanize_error() helper" do
+ it "should return a String given an Exception" do
+ error = Exception.new('Some arbitrary error')
+ humanize_error(error).should == "Some arbitrary error"
+ end
+
+ it "should consider context in lookup" do
+ error = "Connection refused - connect(2)"
+ humanize_error(error).should == t('connection_refused')
+ humanize_error(error, :context => :deltacloud).should ==
t('deltacloud.unreachable')
+ end
+
+ end
+
end
--
1.7.6.2