Exception: IdentityMind::ResponseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/identity_mind/response_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, code) ⇒ ResponseError

Returns a new instance of ResponseError.



5
6
7
8
9
10
11
12
13
14
# File 'lib/identity_mind/response_error.rb', line 5

def initialize(body, code)
  @code = code
  @body = body
  @error_message = extract_error_message(body)

  super(
    ["IdentityMind responded with status #{code}", @error_message]
      .compact.join(' => ')
  )
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/identity_mind/response_error.rb', line 3

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/identity_mind/response_error.rb', line 3

def code
  @code
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



3
4
5
# File 'lib/identity_mind/response_error.rb', line 3

def error_message
  @error_message
end

Instance Method Details

#extract_error_message(body) ⇒ Object



16
17
18
19
20
# File 'lib/identity_mind/response_error.rb', line 16

def extract_error_message(body)
  JSON.parse(body)['error_message']
rescue JSON::ParserError
  nil
end