class HammerCLIForeman::ExceptionHandler

Public Instance Methods

mappings() click to toggle source
Calls superclass method
# File lib/hammer_cli_foreman/exception_handler.rb, line 7
def mappings
  super + [
    [HammerCLIForeman::OperationNotSupportedError, :handle_unsupported_operation],
    [RestClient::InternalServerError, :handle_internal_error],
    [RestClient::Forbidden, :handle_forbidden],
    [RestClient::UnprocessableEntity, :handle_unprocessable_entity],
    [ArgumentError, :handle_argument_error],
  ]
end

Protected Instance Methods

handle_apipie_docloading_error(e) click to toggle source
# File lib/hammer_cli_foreman/exception_handler.rb, line 73
def handle_apipie_docloading_error(e)
  rake_command = 'foreman-rake apipie:cache'
  print_error _("Could not load the API description from the server") + "\n  - " +
              _("is the server down?") + "\n  - " +
              _("was '%s' run on the server when using apipie cache? (typical production settings)") % rake_command
  log_full_error e
  HammerCLI::EX_CONFIG
end
handle_argument_error(e) click to toggle source
# File lib/hammer_cli_foreman/exception_handler.rb, line 33
def handle_argument_error(e)
  print_error e.message
  log_full_error e
  HammerCLI::EX_USAGE
end
handle_forbidden(e) click to toggle source
# File lib/hammer_cli_foreman/exception_handler.rb, line 40
def handle_forbidden(e)
  print_error _("Forbidden - server refused to process the request")
  log_full_error e
  HammerCLI::EX_NOPERM
end
handle_foreman_error(e) click to toggle source
# File lib/hammer_cli_foreman/exception_handler.rb, line 60
def handle_foreman_error(e)
  begin
    response = JSON.parse(e.response)
    response = HammerCLIForeman.record_to_common_format(response) unless response.has_key?('message')
    message = response['message'] || e.message
  rescue JSON::ParserError => parse_e
    message = e.message
  end

  print_error message
  log_full_error e
end
handle_internal_error(e) click to toggle source
# File lib/hammer_cli_foreman/exception_handler.rb, line 27
def handle_internal_error(e)
  handle_foreman_error(e)
  HammerCLI::EX_SOFTWARE
end
handle_not_found(e) click to toggle source
# File lib/hammer_cli_foreman/exception_handler.rb, line 54
def handle_not_found(e)
  handle_foreman_error(e)
  HammerCLI::EX_NOT_FOUND
end
handle_unprocessable_entity(e) click to toggle source
# File lib/hammer_cli_foreman/exception_handler.rb, line 19
def handle_unprocessable_entity(e)
  response = JSON.parse(e.response)
  response = HammerCLIForeman.record_to_common_format(response) unless response.has_key?('message')
  print_error response['message'] || response['full_messages']
  HammerCLI::EX_DATAERR
end
handle_unsupported_operation(e) click to toggle source
# File lib/hammer_cli_foreman/exception_handler.rb, line 47
def handle_unsupported_operation(e)
  print_error e.message
  log_full_error e
  HammerCLI::EX_UNAVAILABLE
end