Exception: Nestful::ResponseError

Inherits:
Error
  • Object
show all
Defined in:
lib/nestful/exceptions.rb

Direct Known Subclasses

ClientError, Redirection, RedirectionLoop, ServerError

Instance Attribute Summary collapse

Attributes inherited from Error

#request

Instance Method Summary collapse

Constructor Details

#initialize(request, response, message = nil) ⇒ ResponseError

Returns a new instance of ResponseError.


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

def initialize(request, response, message = nil)
  super(request, message)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response


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

def response
  @response
end

Instance Method Details

#to_sObject


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

def to_s
  message = "Failed."
  message << "  Response code = #{response.code}." if response.respond_to?(:code)
  message << "  Response message = #{response.message}." if response.respond_to?(:message)

  if response.respond_to?(:body)
    # Error messages need to be in UTF-8
    body = response.body.dup.to_s
    body = body.encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
    body = body[0..255]
    message << "  Response Body = #{body}."
  end

  message
end