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

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

Overview

APIException

Instance Method Summary collapse

Constructor Details

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

Base Class for all the API exceptions



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
71
72
73
74
75
76
# File 'lib/mastercard/core/exceptions.rb', line 41

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

  @message    = message
  @http_status     = http_status
  @raw_error_data = error_data
  @reason_code = nil
  @source = nil
  @description = nil

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

    @raw_error_data = SmartMap.new
    @raw_error_data.setAll(error_data);

    error_data_case_insensitive = parseMap(error_data)

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

      #Case of multiple errors take the first one
      if error_hash.is_a?(Hash)
        initDataFromHash(error_hash)

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

Instance Method Details

#describeObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/mastercard/core/exceptions.rb', line 102

def describe()
  exception = self.class.name
  exception << ": \""
  exception << getMessage()
  exception << "\" (http_status: "
  exception << "%s" % getHttpStatus()
  errorCode = getReasonCode()
  unless errorCode.nil?
    exception << ", reason_code: "
    exception << "%s" % getReasonCode()
  end
  exception << ")"
  return exception
end

#getHttpStatusObject



86
87
88
# File 'lib/mastercard/core/exceptions.rb', line 86

def getHttpStatus()
  return @http_status
end

#getMessageObject



78
79
80
81
82
83
84
# File 'lib/mastercard/core/exceptions.rb', line 78

def getMessage()
  if @description.nil?
    return @message
  else
    return @description
  end
end

#getRawErrorDataObject



98
99
100
# File 'lib/mastercard/core/exceptions.rb', line 98

def getRawErrorData()
  return @raw_error_data
end

#getReasonCodeObject



90
91
92
# File 'lib/mastercard/core/exceptions.rb', line 90

def getReasonCode()
  return @reason_code
end

#getSourceObject



94
95
96
# File 'lib/mastercard/core/exceptions.rb', line 94

def getSource()
  return @source
end

#to_sObject



117
118
119
# File 'lib/mastercard/core/exceptions.rb', line 117

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