ref: refs/heads/master
commit 83d3e6e337c42d477f63cdad151fd6def0de0a73
Author: Duncan Mac-Vicar P
Date: Tue Oct 27 16:29:57 2009 +0100
Use the exception wrapper to extract information and show a meanful
error message
---
.../app/controllers/patch_updates_controller.rb | 3 ++-
.../status/app/controllers/status_controller.rb | 3 ++-
webclient/lib/client_exception.rb | 8 ++++----
webclient/lib/error_constructor.rb | 12 ++++++++----
webclient/test/unit/client_exception_test.rb | 4 ----
5 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/plugins/patch_updates/app/controllers/patch_updates_controller.rb b/plugins/patch_updates/app/controllers/patch_updates_controller.rb
index de249c1..beb3da7 100644
--- a/plugins/patch_updates/app/controllers/patch_updates_controller.rb
+++ b/plugins/patch_updates/app/controllers/patch_updates_controller.rb
@@ -1,4 +1,5 @@
require 'yast/service_resource'
+require 'client_exception'
class PatchUpdatesController < ApplicationController
@@ -42,7 +43,7 @@ class PatchUpdatesController < ApplicationController
end
respond_to do |format|
- format.html { render :partial => "patch_summary", :locals => { :patch => patches_summary, :error => error } }
+ format.html { render :partial => "patch_summary", :locals => { :patch => patches_summary, :error => ClientException.new(error) } }
format.json { render :json => patches_summary }
end
end
diff --git a/plugins/status/app/controllers/status_controller.rb b/plugins/status/app/controllers/status_controller.rb
index 4c2d5f6..4639050 100644
--- a/plugins/status/app/controllers/status_controller.rb
+++ b/plugins/status/app/controllers/status_controller.rb
@@ -1,4 +1,5 @@
require 'yast/service_resource'
+require 'client_exception'
require 'open-uri'
class StatusController < ApplicationController
@@ -173,7 +174,7 @@ class StatusController < ApplicationController
rescue Exception => error
erase_redirect_results #reset all redirects
erase_render_results
- render :partial => "status_summary", :locals => { :status => nil, :error => error } and return
+ render :partial => "status_summary", :locals => { :status => nil, :error => ClientException.new(error) } and return
end
end
diff --git a/webclient/lib/client_exception.rb b/webclient/lib/client_exception.rb
index 0600d1d..13a6650 100644
--- a/webclient/lib/client_exception.rb
+++ b/webclient/lib/client_exception.rb
@@ -14,7 +14,7 @@ require 'error_constructor'
#
class ClientException < Exception
include ErrorConstructor
-
+
# creates an client exception from another
# exception
def initialize(excpt)
@@ -54,8 +54,8 @@ class ClientException < Exception
end
# forward any other method
- def method_missing(name, *args)
- @excpt.send(name, *args)
- end
+ #def method_missing(name, *args)
+ # @excpt.send(name, *args)
+ #end
end
diff --git a/webclient/lib/error_constructor.rb b/webclient/lib/error_constructor.rb
index bb7545e..177d8a3 100644
--- a/webclient/lib/error_constructor.rb
+++ b/webclient/lib/error_constructor.rb
@@ -1,8 +1,12 @@
-# To change this template, choose Tools | Templates
-# and open the template in the editor.
+require 'gettext'
-module ErrorConstructor
- def construct_error (error)
+# from the error data (a hash created from
+# the error response body xml), return a
+# translation if the error type is known
+module ErrorConstructor
+ include GetText
+
+ def construct_error(error)
error = error["error"]
case error["type"]
when "SERVICE_NOT_AVAILABLE"
diff --git a/webclient/test/unit/client_exception_test.rb b/webclient/test/unit/client_exception_test.rb
index 130110a..c19e7ea 100644
--- a/webclient/test/unit/client_exception_test.rb
+++ b/webclient/test/unit/client_exception_test.rb
@@ -1,10 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'client_exception'
-def _(msg)
- msg
-end
-
class ClientExceptionTest < ActiveSupport::TestCase
def test_decode
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org