Exception: CtRegisterMicroservice::APIError

Inherits:
CtRegisterMicroserviceError show all
Defined in:
lib/ct_register_microservice/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_status, response_body, error_message = nil) ⇒ APIError

Returns a new instance of APIError.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ct_register_microservice/errors.rb', line 17

def initialize(http_status, response_body, error_message = nil)
  if response_body
    self.response_body = response_body.strip
  else
    self.response_body = ''
  end
  self.http_status = http_status

  if error_message && error_message.is_a?(String)
    message = error_message
  else
    unless error_message
      begin
        errors = MultiJson.load(response_body) if response_body
        error_array = errors['errors'].map { |n| n['detail'] } if errors.key? 'errors'
      rescue
      end
      error_array ||= []
    end

    if error_array.nil? or error_array.empty?
      message = self.response_body
    else
      message = error_array.join(', ')
    end
  end

  super(message)
end

Instance Attribute Details

#ct_error_codeObject

Returns the value of attribute ct_error_code.



13
14
15
# File 'lib/ct_register_microservice/errors.rb', line 13

def ct_error_code
  @ct_error_code
end

#ct_error_messageObject

Returns the value of attribute ct_error_message.



13
14
15
# File 'lib/ct_register_microservice/errors.rb', line 13

def ct_error_message
  @ct_error_message
end

#ct_error_subcodeObject

Returns the value of attribute ct_error_subcode.



13
14
15
# File 'lib/ct_register_microservice/errors.rb', line 13

def ct_error_subcode
  @ct_error_subcode
end

#ct_error_typeObject

Returns the value of attribute ct_error_type.



13
14
15
# File 'lib/ct_register_microservice/errors.rb', line 13

def ct_error_type
  @ct_error_type
end

#ct_error_user_msgObject

Returns the value of attribute ct_error_user_msg.



13
14
15
# File 'lib/ct_register_microservice/errors.rb', line 13

def ct_error_user_msg
  @ct_error_user_msg
end

#ct_error_user_titleObject

Returns the value of attribute ct_error_user_title.



13
14
15
# File 'lib/ct_register_microservice/errors.rb', line 13

def ct_error_user_title
  @ct_error_user_title
end

#http_statusObject

Returns the value of attribute http_status.



13
14
15
# File 'lib/ct_register_microservice/errors.rb', line 13

def http_status
  @http_status
end

#response_bodyObject

Returns the value of attribute response_body.



13
14
15
# File 'lib/ct_register_microservice/errors.rb', line 13

def response_body
  @response_body
end