Sha256: e0089a26f73fa1901fbab940f4e88286a6c9060515db1e98ab10bdc42e6daa9a

Contents?: true

Size: 1.75 KB

Versions: 14

Compression:

Stored size: 1.75 KB

Contents

class LHC::Error < StandardError

  attr_accessor :response, :_message

  def self.map
    {
      400 => LHC::BadRequest,
      401 => LHC::Unauthorized,
      402 => LHC::PaymentRequired,
      403 => LHC::Forbidden,
      404 => LHC::NotFound,
      405 => LHC::MethodNotAllowed,
      406 => LHC::NotAcceptable,
      407 => LHC::ProxyAuthenticationRequired,
      408 => LHC::RequestTimeout,
      409 => LHC::Conflict,
      410 => LHC::Gone,
      411 => LHC::LengthRequired,
      412 => LHC::PreconditionFailed,
      413 => LHC::RequestEntityTooLarge,
      414 => LHC::RequestUriToLong,
      415 => LHC::UnsupportedMediaType,
      416 => LHC::RequestedRangeNotSatisfiable,
      417 => LHC::ExpectationFailed,
      422 => LHC::UnprocessableEntity,
      423 => LHC::Locked,
      424 => LHC::FailedDependency,
      426 => LHC::UpgradeRequired,

      500 => LHC::InternalServerError,
      501 => LHC::NotImplemented,
      502 => LHC::BadGateway,
      503 => LHC::ServiceUnavailable,
      504 => LHC::GatewayTimeout,
      505 => LHC::HttpVersionNotSupported,
      507 => LHC::InsufficientStorage,
      510 => LHC::NotExtended
    }
  end

  def self.find(response)
    return LHC::Timeout if response.timeout?
    status_code = response.code.to_s[0..2].to_i
    error = map[status_code]
    error ||= LHC::UnknownError
    error
  end

  def initialize(message, response)
    super(message)
    self._message = message
    self.response = response
  end

  def to_s
    request = response.request
    debug = []
    debug << "#{request.method} #{request.url}"
    debug << "Params: #{request.options}"
    debug << "Headers: #{request.headers}"
    debug << "Response Code: #{response.code}"
    debug << response.body
    debug << _message
    debug.join("\n")
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lhc-3.8.0 lib/lhc/error.rb
lhc-3.7.3 lib/lhc/error.rb
lhc-3.7.2 lib/lhc/error.rb
lhc-3.7.2.1 lib/lhc/error.rb
lhc-3.7.1 lib/lhc/error.rb
lhc-3.7.0 lib/lhc/error.rb
lhc-3.7.0.pre1 lib/lhc/error.rb
lhc-3.6.1 lib/lhc/error.rb
lhc-3.6.0 lib/lhc/error.rb
lhc-3.5.5 lib/lhc/error.rb
lhc-3.5.4 lib/lhc/error.rb
lhc-3.5.3 lib/lhc/error.rb
lhc-3.5.2 lib/lhc/error.rb
lhc-3.5.1 lib/lhc/error.rb