class ElvantoAPI::Error
Custom error class for rescuing from all API response-related ElvantoAPI
errors
Attributes
body[R]
Public Class Methods
new(body=nil)
click to toggle source
@param [Hash] body The decoded json response body
Calls superclass method
# 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
Public Instance Methods
error_message()
click to toggle source
@return [Sting] The error message containting in body.
# File lib/elvanto/error.rb, line 17 def error_message set_attrs error = body.fetch('error', nil) if error error["message"] end end
Private Instance Methods
set_attrs()
click to toggle source
# File lib/elvanto/error.rb, line 26 def set_attrs error = body.fetch('error', nil) unless error.nil? error.keys.each do |name| self.class.instance_eval { define_method(name) { error[name] } # Get. define_method("#{name}?") { !!error[name] } # Present. } end end end