Exception: LHC::Error

Inherits:
StandardError
  • Object
show all
Includes:
FixInvalidEncodingConcern
Defined in:
lib/lhc/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, response) ⇒ Error

Returns a new instance of Error.



57
58
59
60
61
# File 'lib/lhc/error.rb', line 57

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

Instance Attribute Details

#_messageObject

Returns the value of attribute _message.



6
7
8
# File 'lib/lhc/error.rb', line 6

def _message
  @_message
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/lhc/error.rb', line 6

def response
  @response
end

Class Method Details

.dupObject



53
54
55
# File 'lib/lhc/error.rb', line 53

def self.dup
  self
end

.find(response) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/lhc/error.rb', line 44

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

.mapObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lhc/error.rb', line 8

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

.to_aObject



63
64
65
# File 'lib/lhc/error.rb', line 63

def self.to_a
  [self]
end

Instance Method Details

#to_sObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/lhc/error.rb', line 67

def to_s
  return response.to_s unless response.is_a?(LHC::Response)

  request = response.request
  return unless request.is_a?(LHC::Request)

  debug = []
  debug << [request.method, request.url].map { |str| self.class.fix_invalid_encoding(str) }.join(' ')
  debug << "Options: #{request.scrubbed_options}"
  debug << "Headers: #{request.scrubbed_headers}"
  debug << "Response Code: #{response.code} (#{response.options[:return_code]})"
  debug << "Response Options: #{response.options}"
  debug << response.body
  debug << _message
  debug.map { |str| self.class.fix_invalid_encoding(str) }.join("\n")
end