Exception: ZammadAPI::ResponseError

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

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation:, response:, resource_class: nil) ⇒ ResponseError

Returns a new instance of ResponseError.



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

def initialize(operation:, response:, resource_class: nil)
  @operation      = operation
  @response       = response
  @resource_class = resource_class
  super(default_message)
end

Instance Attribute Details

#operationObject (readonly)

Returns the value of attribute operation.



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

def operation
  @operation
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



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

def resource_class
  @resource_class
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Class Method Details

.from(response, **kwargs) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/zammad_api/errors.rb', line 28

def self.from(response, **kwargs)
  klass = if response.nil?
            self
          elsif response.status >= 500
            ServerError
          else
            ClientError
          end
  klass.new(response: response, **kwargs)
end

Instance Method Details

#bodyObject



24
25
26
# File 'lib/zammad_api/errors.rb', line 24

def body
  response&.body
end

#statusObject



20
21
22
# File 'lib/zammad_api/errors.rb', line 20

def status
  response&.status
end