Sha256: e3b8234f20e84bd238f74d87e5e104ce0bc37fe4ac3c232f68336c9dfaaf3261

Contents?: true

Size: 853 Bytes

Versions: 6

Compression:

Stored size: 853 Bytes

Contents

require 'hammer_cli/exception_handler'

module HammerCLIForeman
  class ExceptionHandler < HammerCLI::ExceptionHandler

    def mappings
      super + [
        [RestClient::Forbidden, :handle_forbidden],
        [RestClient::UnprocessableEntity, :handle_unprocessable_entity],
        [ArgumentError, :handle_argument_error]
      ]
    end

    protected

    def handle_unprocessable_entity(e)
      response = JSON.parse(e.response)
      response = response[response.keys[0]]

      print_error response["full_messages"]
      HammerCLI::EX_DATAERR
    end


    def handle_argument_error(e)
      print_error e.message
      log_full_error e
      HammerCLI::EX_USAGE
    end

    def handle_forbidden(e)
      print_error "Forbidden - server refused to process the request"
      log_full_error e
      HammerCLI::EX_NOPERM
    end

  end
end



Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hammer_cli_foreman-0.0.10 lib/hammer_cli_foreman/exception_handler.rb
hammer_cli_foreman-0.0.9 lib/hammer_cli_foreman/exception_handler.rb
hammer_cli_foreman-0.0.8 lib/hammer_cli_foreman/exception_handler.rb
hammer_cli_foreman-0.0.7 lib/hammer_cli_foreman/exception_handler.rb
hammer_cli_foreman-0.0.6 lib/hammer_cli_foreman/exception_handler.rb
hammer_cli_foreman-0.0.5 lib/hammer_cli_foreman/exception_handler.rb