Exception: Simplify::ApiException

Inherits:
Exception
  • Object
show all
Defined in:
lib/simplify/apiexception.rb

Overview

Base class for all API exceptions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status, errorData) ⇒ ApiException

Returns a new instance of ApiException.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/simplify/apiexception.rb', line 49

def initialize(message, status, errorData)
  super(message)

  @status = status
  @errorMessage = message        
  @fieldErrors = []
  if errorData != nil
    @errorData = errorData
    @reference = errorData.has_key?('reference') ? errorData['reference'] : nil

    if errorData.has_key?('error')
        error = errorData['error']
        @errorCode = error['code']
        if error.has_key?('message')
            message = error['message']
        end
    end
  end
  super(message)
end

Instance Attribute Details

#errorCodeObject (readonly)

API code for the error.



44
45
46
# File 'lib/simplify/apiexception.rb', line 44

def errorCode
  @errorCode
end

#errorDataObject (readonly)

Error data returned from the API represented as a map.



38
39
40
# File 'lib/simplify/apiexception.rb', line 38

def errorData
  @errorData
end

#errorMessageObject (readonly)

Description of the error.



47
48
49
# File 'lib/simplify/apiexception.rb', line 47

def errorMessage
  @errorMessage
end

#referenceObject (readonly)

Unique reference ID for the API error.



41
42
43
# File 'lib/simplify/apiexception.rb', line 41

def reference
  @reference
end

#statusObject (readonly)

HTML status code (or nil if there is no status code)



35
36
37
# File 'lib/simplify/apiexception.rb', line 35

def status
  @status
end

Instance Method Details

#describeObject

Returns a string descrption of the error.



71
72
73
# File 'lib/simplify/apiexception.rb', line 71

def describe()
  return "#{self.class}: \"#{self.to_s()}\" (status: #{@status}, error code #{@errorCode}, reference: #{@reference})"
end