Exception: Restfully::HTTP::Error

Inherits:
Error show all
Defined in:
lib/restfully/http/error.rb

Direct Known Subclasses

ClientError, ServerError

Constant Summary collapse

STATUS_CODES =
{
  400 => "Bad Request",
  401 => "Authorization Required",
  403 => "Forbiden",
  406 => "Not Acceptable"        
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



12
13
14
15
16
17
18
19
20
21
# File 'lib/restfully/http/error.rb', line 12

def initialize(response)
  @response = response
  response_body = response.body rescue response.raw_body
  if response_body.kind_of?(Hash)
    message = "#{response.status} #{response_body['title']}. #{response_body['message']}"
  else
    message = "#{response.status} #{STATUS_CODES[response.status] || (response_body[0..100]+"...")}"
  end
  super(message)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/restfully/http/error.rb', line 11

def response
  @response
end