Exception: CobotClient::ResponseError

Inherits:
Error
  • Object
show all
Defined in:
lib/cobot_client/errors.rb

Constant Summary collapse

HTTP_CODE =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, response: nil) ⇒ ResponseError

Returns a new instance of ResponseError.



19
20
21
22
23
24
25
26
27
28
# File 'lib/cobot_client/errors.rb', line 19

def initialize(msg = nil, response: nil)
  @response = response

  super(
    [
      "HTTP #{http_code}",
      msg
    ].compact.join(' - ')
  )
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/cobot_client/errors.rb', line 11

def response
  @response
end

Class Method Details

.build(msg = nil, response:) ⇒ Object



13
14
15
16
17
# File 'lib/cobot_client/errors.rb', line 13

def self.build(msg = nil, response:)
  RESPONSE_CODE_TO_ERROR_CLASS
    .fetch(response.code, self)
    .new(msg, response: response)
end

Instance Method Details

#http_bodyObject



30
31
32
# File 'lib/cobot_client/errors.rb', line 30

def http_body
  @response&.body
end

#http_codeObject



34
35
36
# File 'lib/cobot_client/errors.rb', line 34

def http_code
  @response&.code || self.class.const_get(:HTTP_CODE)
end