Class: HammerCLI::ExceptionHandler
- Inherits:
-
Object
- Object
- HammerCLI::ExceptionHandler
- Defined in:
- lib/hammer_cli/exception_handler.rb
Instance Method Summary collapse
- #handle_exception(e, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ ExceptionHandler
constructor
A new instance of ExceptionHandler.
- #mappings ⇒ Object
- #output ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ExceptionHandler
Returns a new instance of ExceptionHandler.
7 8 9 10 |
# File 'lib/hammer_cli/exception_handler.rb', line 7 def initialize(={}) @logger = Logging.logger['Exception'] @output = [:output] end |
Instance Method Details
#handle_exception(e, options = {}) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/hammer_cli/exception_handler.rb', line 27 def handle_exception(e, ={}) @options = handler = mappings.reverse.find { |m| e.class.respond_to?(:"<=") ? e.class <= m[0] : false } @logger.debug "Using exception handler #{self.class}##{handler[1]}" return send(handler[1], e) if handler raise e end |
#mappings ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hammer_cli/exception_handler.rb', line 12 def mappings [ [Exception, :handle_general_exception], # catch all [Clamp::HelpWanted, :handle_help_wanted], [Clamp::UsageError, :handle_usage_exception], [RestClient::ResourceNotFound, :handle_not_found], [RestClient::Unauthorized, :handle_unauthorized], [RestClient::SSLCertificateNotVerified, :handle_ssl_cert_not_verified], [OpenSSL::SSL::SSLError, :handle_ssl_error], [ApipieBindings::DocLoadingError, :handle_apipie_docloading_error], [ApipieBindings::MissingArgumentsError, :handle_apipie_missing_arguments_error], [HammerCLI::ModuleDisabledButRequired, :handle_generic_config_error] ] end |