Skip to content

Commit

Permalink
move catch_registration_errors() to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 26, 2014
1 parent 6680b92 commit efd3edb
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 52 deletions.
3 changes: 2 additions & 1 deletion src/Makefile.am
Expand Up @@ -18,7 +18,8 @@ ylib_DATA = \
lib/registration/storage.rb \
lib/registration/repo_state.rb \
lib/registration/registration.rb \
lib/registration/helpers.rb
lib/registration/helpers.rb \
lib/registration/scc_helpers.rb

ylibyastdir = @ylibdir@/yast
ylibyast_DATA = \
Expand Down
5 changes: 3 additions & 2 deletions src/clients/inst_scc.rb
Expand Up @@ -29,6 +29,7 @@

require "registration/exceptions"
require "registration/helpers"
require "registration/scc_helpers"
require "registration/sw_mgmt"
require "registration/repo_state"
require "registration/storage"
Expand Down Expand Up @@ -111,7 +112,7 @@ def register_base_system
url = ::Registration::Helpers.registration_url
@registration = ::Registration::Registration.new(url)

::Registration::Helpers.catch_registration_errors do
::Registration::SccHelpers.catch_registration_errors do
Popup.Feedback(_("Registering the System..."),
_("Contacting the SUSE Customer Center server")) do

Expand Down Expand Up @@ -521,7 +522,7 @@ def register_selected_addons
}
end

ret = ::Registration::Helpers.catch_registration_errors do
ret = ::Registration::SccHelpers.catch_registration_errors do
product_services = ::Registration::Helpers.run_with_feedback(
n_("Registering Product...", "Registering Products...", products.size),
_("Contacting the SUSE Customer Center server")) do
Expand Down
4 changes: 3 additions & 1 deletion src/clients/scc_auto.rb
Expand Up @@ -31,6 +31,8 @@

require "registration/storage"
require "registration/registration"
require "registration/helpers"
require "registration/scc_helpers"

module Yast
class SccAutoClient < Client
Expand Down Expand Up @@ -157,7 +159,7 @@ def write

end

ret = ::Registration::Helpers.catch_registration_errors do
ret = ::Registration::SccHelpers.catch_registration_errors do
# register the system
Popup.Feedback(_("Registering the System..."),
_("Contacting the SUSE Customer Center server")) do
Expand Down
48 changes: 0 additions & 48 deletions src/lib/registration/helpers.rb
Expand Up @@ -127,54 +127,6 @@ def self.run_network_configuration
Yast::WFM.call("inst_lan")
end

def self.catch_registration_errors(&block)
begin
yield
true
rescue SccApi::NoNetworkError
# Error popup
if Yast::Mode.installation && Yast::Popup.YesNo(
_("Network is not configured, the registration server cannot be reached.\n" +
"Do you want to configure the network now?") )
Registration::Helpers::run_network_configuration
end
false
rescue SccApi::NotAuthorized
# Error popup
Yast::Report.Error(_("The email address or the registration\ncode is not valid."))
false
rescue Timeout::Error
# Error popup
Yast::Report.Error(_("Connection time out."))
false
rescue SccApi::ErrorResponse => e
# TODO FIXME: display error details from the response
Yast::Report.Error(_("Registration server error.\n\nRetry registration later."))
false
rescue SccApi::HttpError => e
case e.response
when Net::HTTPClientError
Yast::Report.Error(_("Registration client error."))
when Net::HTTPServerError
Yast::Report.Error(_("Registration server error.\n\nRetry registration later."))
else
Yast::Report.Error(_("Registration failed."))
end
false
rescue ::Registration::ServiceError => e
log.error("Service error: #{e.message % e.service}")
Yast::Report.Error(_(e.message) % e.service)
false
rescue ::Registration::PkgError => e
log.error("Pkg error: #{e.message}")
Yast::Report.Error(_(e.message))
false
rescue Exception => e
log.error("SCC registration failed: #{e}, #{e.backtrace}")
Yast::Report.Error(_("Registration failed."))
false
end
end

private

Expand Down
92 changes: 92 additions & 0 deletions src/lib/registration/scc_helpers.rb
@@ -0,0 +1,92 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2014 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# 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, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
#
#

require "yast"
require "scc_api"

require "registration/helpers"
require "registration/exceptions"

module Registration

class SccHelpers
include Yast::Logger
extend Yast::I18n

textdomain "registration"

Yast.import "Mode"
Yast.import "Popup"
Yast.import "Report"

def self.catch_registration_errors(&block)
begin
yield
true
rescue SccApi::NoNetworkError
# Error popup
if Yast::Mode.installation && Yast::Popup.YesNo(
_("Network is not configured, the registration server cannot be reached.\n" +
"Do you want to configure the network now?") )
Registration::Helpers::run_network_configuration
end
false
rescue SccApi::NotAuthorized
# Error popup
Yast::Report.Error(_("The email address or the registration\ncode is not valid."))
false
rescue Timeout::Error
# Error popup
Yast::Report.Error(_("Connection time out."))
false
rescue SccApi::ErrorResponse => e
# TODO FIXME: display error details from the response
Yast::Report.Error(_("Registration server error.\n\nRetry registration later."))
false
rescue SccApi::HttpError => e
case e.response
when Net::HTTPClientError
Yast::Report.Error(_("Registration client error."))
when Net::HTTPServerError
Yast::Report.Error(_("Registration server error.\n\nRetry registration later."))
else
Yast::Report.Error(_("Registration failed."))
end
false
rescue ::Registration::ServiceError => e
log.error("Service error: #{e.message % e.service}")
Yast::Report.Error(_(e.message) % e.service)
false
rescue ::Registration::PkgError => e
log.error("Pkg error: #{e.message}")
Yast::Report.Error(_(e.message))
false
rescue Exception => e
log.error("SCC registration failed: #{e}, #{e.backtrace}")
Yast::Report.Error(_("Registration failed."))
false
end
end

end
end

0 comments on commit efd3edb

Please sign in to comment.