Exception: Jirafe::Error::ResourceError

Inherits:
JirafeError
  • Object
show all
Defined in:
lib/jirafe/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResourceError

Returns a new instance of ResourceError.



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

def initialize(response)
  parsed_error = JSON.parse(response.body) rescue response.body
  parsed_message = parsed_error["error"]["message"] rescue parsed_error
  parsed_message_data = parsed_error["error"]["data"].join(', ') rescue nil
  @message_data = JSON.parse(response.body)["error"]["data"] rescue nil
  @http_status = response.code
  @http_body = response.body
  @json_body = JSON.parse(response.body) rescue {}
  status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
  @message = "#{status_string}#{parsed_message} #{parsed_message_data}"
end

Instance Attribute Details

#http_bodyObject (readonly)

Returns the value of attribute http_body.



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

def http_body
  @http_body
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



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

def http_status
  @http_status
end

#json_bodyObject (readonly)

Returns the value of attribute json_body.



9
10
11
# File 'lib/jirafe/error.rb', line 9

def json_body
  @json_body
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/jirafe/error.rb', line 6

def message
  @message
end

Instance Method Details

#to_sObject



23
24
25
# File 'lib/jirafe/error.rb', line 23

def to_s
  @message
end