Exception: Alula::M2MError

Inherits:
AlulaError show all
Defined in:
lib/alula/errors.rb

Instance Attribute Summary collapse

Attributes inherited from AlulaError

#error, #http_status, #message, #raw_response

Class Method Summary collapse

Methods inherited from AlulaError

critical_error_for_response, error_for_response, errors_for_response, gateway_error_for_response, #initialize, #ok?

Constructor Details

This class inherits a constructor from Alula::AlulaError

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



236
237
238
# File 'lib/alula/errors.rb', line 236

def error_code
  @error_code
end

Class Method Details

.build_message(error, code) ⇒ Object



255
256
257
258
259
260
# File 'lib/alula/errors.rb', line 255

def self.build_message(error, code)
  return error unless error.to_s.strip.empty?
  return "M2M request failed with code #{code}" if code

  'M2M request failed'
end

.for_response(response) ⇒ Object



238
239
240
241
242
243
244
# File 'lib/alula/errors.rb', line 238

def self.for_response(response)
  if response.data['Success'] == false
    self.m2m_error_for_response(response)
  else
    super response
  end
end

.m2m_error_for_response(response) ⇒ Object



248
249
250
251
252
253
# File 'lib/alula/errors.rb', line 248

def self.m2m_error_for_response(response)
  error_code = response.data['ErrorCode']
  error = response.data['ErrorString']
  message = self.build_message(error, error_code)
  BadRequestError.new(message)
end