Exception: MasterCard::Core::Exceptions::APIException
- Inherits:
-
StandardError
- Object
- StandardError
- MasterCard::Core::Exceptions::APIException
- Includes:
- Model
- Defined in:
- lib/mastercard/core/exceptions.rb
Overview
APIException
Instance Method Summary collapse
- #describe ⇒ Object
- #getHttpStatus ⇒ Object
- #getMessage ⇒ Object
- #getRawErrorData ⇒ Object
- #getReasonCode ⇒ Object
- #getSource ⇒ Object
-
#initialize(message, http_status = nil, error_data = nil) ⇒ APIException
constructor
Base Class for all the API exceptions.
- #to_s ⇒ Object
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(,http_status=nil, error_data=nil) #Call the base class constructor super() = @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
#describe ⇒ Object
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 |
#getHttpStatus ⇒ Object
86 87 88 |
# File 'lib/mastercard/core/exceptions.rb', line 86 def getHttpStatus() return @http_status end |
#getMessage ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/mastercard/core/exceptions.rb', line 78 def getMessage() if @description.nil? return else return @description end end |
#getRawErrorData ⇒ Object
98 99 100 |
# File 'lib/mastercard/core/exceptions.rb', line 98 def getRawErrorData() return @raw_error_data end |
#getReasonCode ⇒ Object
90 91 92 |
# File 'lib/mastercard/core/exceptions.rb', line 90 def getReasonCode() return @reason_code end |
#getSource ⇒ Object
94 95 96 |
# File 'lib/mastercard/core/exceptions.rb', line 94 def getSource() return @source end |
#to_s ⇒ Object
117 118 119 |
# File 'lib/mastercard/core/exceptions.rb', line 117 def to_s() return '%s' % describe() end |