Exception: ElvantoAPI::Error

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

Overview

Custom error class for rescuing from all API response-related ElvantoAPI errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body = nil) ⇒ Error

Returns a new instance of Error.

Parameters:

  • body (Hash) (defaults to: nil)

    The decoded json response body



8
9
10
11
12
13
# File 'lib/elvanto/error.rb', line 8

def initialize(body=nil)
  @body = Utils.indifferent_read_access(body)
  unless body.nil?
    super error_message
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/elvanto/error.rb', line 5

def body
  @body
end

Instance Method Details

#error_messageSting

Returns The error message containting in body.

Returns:

  • (Sting)

    The error message containting in body.



17
18
19
20
21
22
23
# File 'lib/elvanto/error.rb', line 17

def error_message
  set_attrs
  error = body.fetch('error', nil)
  if error
    error["message"]
  end
end