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.



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

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

  ## Try to help out with the message
  if self.body
    if error = self.body['error']
      message = "#{message} (#{error})"
    end
  elsif self.response
    message = "#{message} (\"#{self.response.inspect}\")"
  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.



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

def body
  @body
end

#responseObject

The Faraday::Response object which led to this exception.



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

def response
  @response
end