Sha256: ec3b9b5cd2094ade5d6726432b5c899d6fc7a62c3559b434bb7ea40a88b24dd7

Contents?: true

Size: 1.7 KB

Versions: 8

Compression:

Stored size: 1.7 KB

Contents

require 'json'

module Puppet::Network::HTTP::Error
  Issues = Puppet::Network::HTTP::Issues

  class HTTPError < Exception
    attr_reader :status, :issue_kind

    def initialize(message, status, issue_kind)
      super(message)
      @status = status
      @issue_kind = issue_kind
    end

    def to_json
      JSON({:message => message, :issue_kind => @issue_kind})
    end
  end

  class HTTPNotAcceptableError < HTTPError
    CODE = 406
    def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
      super("Not Acceptable: " + message, CODE, issue_kind)
    end
  end

  class HTTPNotFoundError < HTTPError
    CODE = 404
    def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
      super("Not Found: " + message, CODE, issue_kind)
    end
  end

  class HTTPNotAuthorizedError < HTTPError
    CODE = 403
    def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
      super("Not Authorized: " + message, CODE, issue_kind)
    end
  end

  class HTTPBadRequestError < HTTPError
    CODE = 400
    def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
      super("Bad Request: " + message, CODE, issue_kind)
    end
  end

  class HTTPMethodNotAllowedError < HTTPError
    CODE = 405
    def initialize(message, issue_kind = Issues::RUNTIME_ERROR)
      super("Method Not Allowed: " + message, CODE, issue_kind)
    end
  end

  class HTTPServerError < HTTPError
    CODE = 500

    attr_reader :backtrace

    def initialize(original_error, issue_kind = Issues::RUNTIME_ERROR)
      super("Server Error: " + original_error.message, CODE, issue_kind)
      @backtrace = original_error.backtrace
    end

    def to_json
      JSON({:message => message, :issue_kind => @issue_kind})
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-4.8.1 lib/puppet/network/http/error.rb
puppet-4.8.1-x86-mingw32 lib/puppet/network/http/error.rb
puppet-4.8.1-x64-mingw32 lib/puppet/network/http/error.rb
puppet-4.8.1-universal-darwin lib/puppet/network/http/error.rb
puppet-4.8.0 lib/puppet/network/http/error.rb
puppet-4.8.0-x86-mingw32 lib/puppet/network/http/error.rb
puppet-4.8.0-x64-mingw32 lib/puppet/network/http/error.rb
puppet-4.8.0-universal-darwin lib/puppet/network/http/error.rb