ref: refs/heads/network commit 512b398c9155979397e6137f167ec0c0269de1a0 Author: Josef Reidinger <jreidinger@suse.cz> Date: Thu Sep 10 10:24:29 2009 +0200 add working reporting errors from backend --- .../test/functional/systemtime_controller_test.rb | 3 +- .../app/controllers/application_controller.rb | 25 +++++++++++++++++++- .../app/controllers/controlpanel_controller.rb | 2 +- .../views/shared/backendexception_trap.html.erb | 16 ++++++++++++ webclient/lib/error_constructor.rb | 9 +++++++ 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/plugins/systemtime/test/functional/systemtime_controller_test.rb b/plugins/systemtime/test/functional/systemtime_controller_test.rb index b42f503..b9bb948 100644 --- a/plugins/systemtime/test/functional/systemtime_controller_test.rb +++ b/plugins/systemtime/test/functional/systemtime_controller_test.rb @@ -96,8 +96,7 @@ class SystemtimeControllerTest < ActionController::TestCase def test_commit YaST::ServiceResource.stubs(:proxy_for).with('org.opensuse.yast.modules.yapi.time').returns(@proxy) - post :update, { :currenttime => "2009-07-02 - 12:18:00", :date => { :date => "2009-07-02 - 12:18:00/2009-07-02 - 12:18:00" }, :utc => "true" } - + post :update, { :currenttime => "2009-07-02 - 12:18:00", :date => { :date => "2009-07-02 - 12:18:00/2009-07-02 - 12:18:00" }, :utc => "true" } assert_response :redirect assert_redirected_to :action => "index" diff --git a/webclient/app/controllers/application_controller.rb b/webclient/app/controllers/application_controller.rb index bff673b..3c2b0ef 100644 --- a/webclient/app/controllers/application_controller.rb +++ b/webclient/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ require 'open-uri' class ApplicationController < ActionController::Base - layout 'main' + layout 'main' def redirect_success if session[:wizard_current] and session[:wizard_current] != "FINISH" @@ -15,9 +15,14 @@ class ApplicationController < ActionController::Base end end + #catch webservice errors rescue_from Exception, :with => :exception_trap + rescue_from ActiveResource::ServerError, :with => :backendexception_trap + + include AuthenticatedSystem + include ErrorConstructor begin require 'gettext_rails' @@ -32,6 +37,24 @@ class ApplicationController < ActionController::Base super end + + def backendexception_trap(e) + logger.debug "Backend exception trap" + logger.debug e.response.body.inspect + if e.response.code =~ /.*503.*/ + logger.debug "get backend Exception" + error = Hash.from_xml e.response.body + err_msg = construct_error(error) + if request.xhr? + render :text => err_msg + else + render :template => "shared/backendexception_trap", :locals => {:error => err_msg} + end + else + exception_trap(e) + end + end + def exception_trap(e) logger.error "***" + e.to_s diff --git a/webclient/app/controllers/controlpanel_controller.rb b/webclient/app/controllers/controlpanel_controller.rb index f9c2037..8317134 100644 --- a/webclient/app/controllers/controlpanel_controller.rb +++ b/webclient/app/controllers/controlpanel_controller.rb @@ -113,7 +113,7 @@ class ControlpanelController < ApplicationController shortcuts_fn = File.join(plugin.directory, 'shortcuts.yml') if File.exists?(shortcuts_fn) logger.debug "Shortcuts at #{plugin.directory}" - shortcuts_data = YAML::load(File.open(shortcuts_fn)) + shortcutsdata = YAML::load(File.open(shortcuts_fn)) return nil unless shortcutsdata.is_a? Hash # now go over each shortcut and add it to the modules shortcutsdata.each do |k,v| diff --git a/webclient/app/views/shared/backendexception_trap.html.erb b/webclient/app/views/shared/backendexception_trap.html.erb new file mode 100644 index 0000000..d1068fb --- /dev/null +++ b/webclient/app/views/shared/backendexception_trap.html.erb @@ -0,0 +1,16 @@ + +<h1><%= _("This is embarrasing....") %></h1> + +<p><%= _("Problem occur on target machine.") %></p> + +<h3><%= _("Problem:") %></h3> + +<p> + <pre> + <%= h error %> + </pre> +</p> + + + + diff --git a/webclient/lib/error_constructor.rb b/webclient/lib/error_constructor.rb new file mode 100644 index 0000000..8ec12fa --- /dev/null +++ b/webclient/lib/error_constructor.rb @@ -0,0 +1,9 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +module ErrorConstructor + def construct_error (error) + #now use stupid unlocalized message + return error["error"]["description"] + end +end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org