Exception: HyperResource::ResponseError

Inherits:
Exception
  • Object
show all
Defined in:
lib/hyper_resource/exceptions.rb

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Attributes inherited from Exception

#cause

Instance Method Summary collapse

Constructor Details

#initialize(message, attrs = {}) ⇒ ResponseError

Returns a new instance of ResponseError.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hyper_resource/exceptions.rb', line 20

def initialize(message, attrs={}) # @private
  self.response = attrs[:response]
  self.body = attrs[:body]

  ## Try to help out with the message
  if body
    if (error = body['error'])
      message = "#{message} (#{error})"
    end
    if (error_message = body['message'])
      message = "#{message} (#{error_message})"
    end
  elsif response
    message = "#{message} (#{response.body})"
  end

  super(message, attrs)
end

Instance Attribute Details

#bodyObject

The deserialized response body which led to this exception. May be blank, e.g. in case of deserialization errors.



18
19
20
# File 'lib/hyper_resource/exceptions.rb', line 18

def body
  @body
end

#responseObject

The HTTPClient::Message object which led to this exception.



14
15
16
# File 'lib/hyper_resource/exceptions.rb', line 14

def response
  @response
end