Exception: MasterCard::Core::Exceptions::InvalidRequestException

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

Overview

InvalidRequestException

Instance Method Summary collapse

Methods inherited from APIException

#getErrorCode, #getErrorData, #getMessage, #getStatus

Constructor Details

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

Exception raised when the API request contains errors.



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/mastercard/core/exceptions.rb', line 182

def initialize(message=nil,status=nil,error_data=nil)

  if status.nil?
      status = 400
  end

  #Call the base class constructor
  super(message,status,error_data)

  @fieldErrors = []

  #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

      initFieldDataFromHash(error_hash)

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

Instance Method Details

#describeObject



227
228
229
230
231
232
233
# File 'lib/mastercard/core/exceptions.rb', line 227

def describe
  des = super()
  @fieldErrors.each do |field_error|
    des << "\n #{field_error}"
  end
  return des
end

#getFieldErrorsObject



223
224
225
# File 'lib/mastercard/core/exceptions.rb', line 223

def getFieldErrors
  return @fieldErrors
end

#hasFieldErrorsObject



219
220
221
# File 'lib/mastercard/core/exceptions.rb', line 219

def hasFieldErrors
  return @fieldErrors.length != 0
end

#to_sObject



235
236
237
# File 'lib/mastercard/core/exceptions.rb', line 235

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