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 77 78 79 80 81 82 83 84 85 |
# File 'lib/mastercard/core/exceptions.rb', line 41 def initialize(,http_status=nil, error_data=nil) #Call the base class constructor super() @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_hash = error_data_case_insensitive["errors"] if (error_hash.is_a?(Hash) && error_hash.key?("error")) error_hash = error_hash["error"] end if error_hash.is_a?(Array) error_hash = error_hash[0] end #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
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/mastercard/core/exceptions.rb', line 111 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
95 96 97 |
# File 'lib/mastercard/core/exceptions.rb', line 95 def getHttpStatus() return @http_status end |
#getMessage ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/mastercard/core/exceptions.rb', line 87 def getMessage() if @description.nil? return @message else return @description end end |
#getRawErrorData ⇒ Object
107 108 109 |
# File 'lib/mastercard/core/exceptions.rb', line 107 def getRawErrorData() return @raw_error_data end |
#getReasonCode ⇒ Object
99 100 101 |
# File 'lib/mastercard/core/exceptions.rb', line 99 def getReasonCode() return @reason_code end |
#getSource ⇒ Object
103 104 105 |
# File 'lib/mastercard/core/exceptions.rb', line 103 def getSource() return @source end |
#to_s ⇒ Object
126 127 128 |
# File 'lib/mastercard/core/exceptions.rb', line 126 def to_s() return '%s' % describe() end |