Exception: Restify::ResponseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/restify/error.rb

Overview

A ResponseError is returned on a non-successful response from server. Usually it will either be a ClientError or a ServerError.

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseError

Returns a new instance of ResponseError.



37
38
39
40
41
# File 'lib/restify/error.rb', line 37

def initialize(response)
  @response = response
  super "#{response.message} (#{response.code}) for `#{response.uri}':\n" \
        "  #{errors.inspect}"
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



35
36
37
# File 'lib/restify/error.rb', line 35

def response
  @response
end

Instance Method Details

#codeFixnum

Return response status code.

Returns:

  • (Fixnum)

    Response status code.

See Also:



57
58
59
# File 'lib/restify/error.rb', line 57

def code
  response.code
end

#errorsObject

Return hash or array of errors if response included such a thing otherwise it returns nil.



64
65
66
67
68
69
70
71
72
# File 'lib/restify/error.rb', line 64

def errors
  if response.decoded_body
    response.decoded_body['errors'] ||
      response.decoded_body[:errors] ||
      response.decoded_body
  else
    response.body
  end
end

#statusSymbol

Return response status.

Returns:

  • (Symbol)

    Response status.

See Also:



48
49
50
# File 'lib/restify/error.rb', line 48

def status
  response.status
end