[yast-devel] Re: [yast-commit] <web-client> master : cleanup exception handling espl. not running collectd (bnc#555205)
![](https://seccdn.libravatar.org/avatar/f9a9cf77af20d925b328ee8c95c0068c.jpg?s=120&d=mm&r=g)
Stefan Schubert write:
ref: refs/heads/master commit 4ab44123fb323d1dd41e6616a80c1baeeae3d4ca Author: Stefan Schubert <schubi@suse.de> Date: Thu Nov 19 11:08:47 2009 +0100
cleanup exception handling espl. not running collectd (bnc#555205) --- .../status/app/controllers/status_controller.rb | 40 ++++++++++++++----- 1 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/plugins/status/app/controllers/status_controller.rb b/plugins/status/app/controllers/status_controller.rb index 4936a53..ca521b8 100644 --- a/plugins/status/app/controllers/status_controller.rb +++ b/plugins/status/app/controllers/status_controller.rb @@ -154,15 +154,24 @@ class StatusController < ApplicationController
def index return unless client_permissions - - log = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.logs') - @logs = log.find(:all) - flash[:notice] = _("No data found for showing system status.") unless create_data - limits_reached - logger.debug "limits reached for #{@limits_list[:reached].inspect}" + begin + log = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.logs') + @logs = log.find(:all) + flash[:notice] = _("No data found for showing system status.") unless create_data + limits_reached + logger.debug "limits reached for #{@limits_list[:reached].inspect}" + rescue ActiveResource::ServerError => error + error_hash = Hash.from_xml error.response.body + logger.warn error_hash.inspect + if error_hash["error"] && + (error_hash["error"]["type"] == "SERVICE_NOT_RUNNING" || error_hash["error"]["type"] == "NO_PERM") + flash[:error] = error_hash["error"]["description"]
Hi, few notes. You can benefit here from clientException class, so you can use exception = ClinetException.new(error) if ["SERVICE_NOT_RUNNING","NO_PERM"].include? exception.backend_exception_type flash[:error] = exception.message #bonus you have localized message from ErrorConstructor class (just add localization string here) else ... end
+ else + raise error + end + end end
- def show_summary return unless client_permissions begin @@ -173,10 +182,19 @@ class StatusController < ApplicationController status = _("No data found for showing system status.") end render :partial => "status_summary", :locals => { :status => status, :error => nil } - rescue Exception => error - erase_redirect_results #reset all redirects - erase_render_results - render :partial => "status_summary", :locals => { :status => nil, :error => ClientException.new(error) } and return + rescue ActiveResource::ClientError => error + logger.warn error.inspect + render :partial => "status_summary", :locals => { :status => nil, :error => ClientException.new(error) } and return + rescue ActiveResource::ServerError => error + error_hash = Hash.from_xml error.response.body + logger.warn error_hash.inspect + if error_hash["error"] && + (error_hash["error"]["type"] == "SERVICE_NOT_RUNNING" || error_hash["error"]["type"] == "NO_PERM") + status = error_hash["error"]["description"] same as above.
Josef
+ render :partial => "status_summary", :locals => { :status => status, :error => nil } + else + render :partial => "status_summary", :locals => { :status => nil, :error => ClientException.new(error) } + end end end
-- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast (language,time,basesystem,ntp) -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/55aa23a230c2b775aa3cdca886acb2b8.jpg?s=120&d=mm&r=g)
Josef Reidinger schrieb:
Stefan Schubert write:
ref: refs/heads/master commit 4ab44123fb323d1dd41e6616a80c1baeeae3d4ca Author: Stefan Schubert <schubi@suse.de> Date: Thu Nov 19 11:08:47 2009 +0100
cleanup exception handling espl. not running collectd (bnc#555205) --- .../status/app/controllers/status_controller.rb | 40 ++++++++++++++----- 1 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/plugins/status/app/controllers/status_controller.rb b/plugins/status/app/controllers/status_controller.rb index 4936a53..ca521b8 100644 --- a/plugins/status/app/controllers/status_controller.rb +++ b/plugins/status/app/controllers/status_controller.rb @@ -154,15 +154,24 @@ class StatusController < ApplicationController
def index return unless client_permissions - - log = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.logs') - @logs = log.find(:all) - flash[:notice] = _("No data found for showing system status.") unless create_data - limits_reached - logger.debug "limits reached for #{@limits_list[:reached].inspect}" + begin + log = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.logs') + @logs = log.find(:all) + flash[:notice] = _("No data found for showing system status.") unless create_data + limits_reached + logger.debug "limits reached for #{@limits_list[:reached].inspect}" + rescue ActiveResource::ServerError => error + error_hash = Hash.from_xml error.response.body + logger.warn error_hash.inspect + if error_hash["error"] && + (error_hash["error"]["type"] == "SERVICE_NOT_RUNNING" || error_hash["error"]["type"] == "NO_PERM") + flash[:error] = error_hash["error"]["description"]
I think that this is the "second" best way :-) The best way would be to tell the service which language currently is selected in the UI. So, the service can return messages in the correct language. Especially for cases like user module where error messages comes from the yast2-user module. Another example would be SuSERegister which has also the possibility to return messages in the selected translation.
Hi, few notes. You can benefit here from clientException class, so you can use exception = ClinetException.new(error) if ["SERVICE_NOT_RUNNING","NO_PERM"].include? exception.backend_exception_type flash[:error] = exception.message #bonus you have localized message from ErrorConstructor class (just add localization string here) else ... end
+ else + raise error + end + end end
- def show_summary return unless client_permissions begin @@ -173,10 +182,19 @@ class StatusController < ApplicationController status = _("No data found for showing system status.") end render :partial => "status_summary", :locals => { :status => status, :error => nil } - rescue Exception => error - erase_redirect_results #reset all redirects - erase_render_results - render :partial => "status_summary", :locals => { :status => nil, :error => ClientException.new(error) } and return + rescue ActiveResource::ClientError => error + logger.warn error.inspect + render :partial => "status_summary", :locals => { :status => nil, :error => ClientException.new(error) } and return + rescue ActiveResource::ServerError => error + error_hash = Hash.from_xml error.response.body + logger.warn error_hash.inspect + if error_hash["error"] && + (error_hash["error"]["type"] == "SERVICE_NOT_RUNNING" || error_hash["error"]["type"] == "NO_PERM") + status = error_hash["error"]["description"]
same as above.
Josef
+ render :partial => "status_summary", :locals => { :status => status, :error => nil } + else + render :partial => "status_summary", :locals => { :status => nil, :error => ClientException.new(error) } + end end end
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (2)
-
Josef Reidinger
-
Stefan Schubert