Exception: Zesty::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code, response_body, response_headers) ⇒ Error

Returns a new instance of Error.



21
22
23
24
25
26
# File 'lib/zesty/error.rb', line 21

def initialize(message, code, response_body, response_headers)
  super(message)
  @code = code
  @response_body = response_body
  @response_headers = response_headers
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/zesty/error.rb', line 4

def code
  @code
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



4
5
6
# File 'lib/zesty/error.rb', line 4

def response_body
  @response_body
end

#response_headersObject (readonly)

Returns the value of attribute response_headers.



4
5
6
# File 'lib/zesty/error.rb', line 4

def response_headers
  @response_headers
end

Class Method Details

.from_response(data, response) ⇒ Object



7
8
9
10
# File 'lib/zesty/error.rb', line 7

def from_response(data, response)
  message = parse_error(data) || response.to_s
  new(message, response.code, response.to_s, response.headers.to_h)
end

Instance Method Details

#to_hObject



28
29
30
31
32
33
34
35
# File 'lib/zesty/error.rb', line 28

def to_h
  {
    code: code,
    message: message,
    response_body: response_body,
    response_headers: response_headers
  }
end