Exception: MasterCard::Core::Exceptions::APIException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/mastercard/core/exceptions.rb

Overview

APIException

Instance Method Summary collapse

Constructor Details

#initialize(message, status = nil, error_data = nil) ⇒ APIException

Base Class for all the API exceptions



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/mastercard/core/exceptions.rb', line 37

def initialize(message,status=nil, error_data=nil)
  #Call the base class constructor
  super(message)

  @message    = message
  @status     = status
  @error_data = error_data
  @error_code = nil

  #If error_data is not nil set the appropriate message
  unless error_data.nil?

    error_hash = Hash.new
    # If error_data is of type hash and has Key 'Errors' which has a key 'Error'
    if error_data.is_a?(Hash) && error_data.key?("Errors") && error_data["Errors"].key?("Error")

      error_hash = error_data["Errors"]["Error"]

      #Case of multiple errors take the first one
      if error_hash.is_a?(Array)
        error_hash = error_hash[0]
      end

      initDataFromHash(error_hash)

    #If error Data is of Type Array
    elsif error_data.is_a?(Array)
      #Take the first error
      error_hash = error_data[0]
      initDataFromHash(error_hash)
    end
  end

end

Instance Method Details

#describeObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mastercard/core/exceptions.rb', line 88

def describe()
  exception = self.class.name
  exception << ": \""
  exception << getMessage()
  exception << "\" (status: "
  exception << "%s" % getStatus()
  errorCode = getErrorCode()
  unless errorCode.nil?
    exception << ", error code: "
    exception << "%s" % getErrorCode()
  end
  exception << ")"
  return exception
end

#getErrorCodeObject



80
81
82
# File 'lib/mastercard/core/exceptions.rb', line 80

def getErrorCode()
  return @error_code
end

#getErrorDataObject



84
85
86
# File 'lib/mastercard/core/exceptions.rb', line 84

def getErrorData()
  return @error_data
end

#getMessageObject



72
73
74
# File 'lib/mastercard/core/exceptions.rb', line 72

def getMessage()
  return @message
end

#getStatusObject



76
77
78
# File 'lib/mastercard/core/exceptions.rb', line 76

def getStatus()
  return @status
end

#to_sObject



103
104
105
# File 'lib/mastercard/core/exceptions.rb', line 103

def to_s()
  return '%s' % describe()
end