Exception: EVSS::ServiceException

Inherits:
Common::Exceptions::BaseError show all
Defined in:
lib/evss/service_exception.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Common::Exceptions::BaseError

#errors, #i18n_data, #i18n_field, #i18n_interpolated, #i18n_key, #log_to_sentry?, #message, #sentry_type, #status_code

Constructor Details

#initialize(original_body) ⇒ ServiceException

Returns a new instance of ServiceException.



9
10
11
12
13
# File 'lib/evss/service_exception.rb', line 9

def initialize(original_body)
  @messages = original_body['messages']
  @key = error_key || 'evss.unmapped_service_exception'
  super
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/evss/service_exception.rb', line 7

def key
  @key
end

#messagesObject (readonly)

Returns the value of attribute messages.



7
8
9
# File 'lib/evss/service_exception.rb', line 7

def messages
  @messages
end

Instance Method Details

#error_keyObject (private)



17
18
19
20
21
22
23
24
25
# File 'lib/evss/service_exception.rb', line 17

def error_key
  # in case of multiple errors, the ordering of ERROR_MAP is used to decide which error is highest priority.
  # NOTE: The ordering of ERROR_MAP takes precedence over both 1) how the error messages were ordered in the
  # EVSS response and 2) the "severity" keys of those messages.
  error_map = self.class::ERROR_MAP.select { |k, _v| messages_has_key?(k) }
  return error_map.values.first unless error_map.empty?

  self.class::ERROR_MAP[:default]
end

#messages_has_key?(key) ⇒ Boolean (private)

Returns:

  • (Boolean)


27
28
29
# File 'lib/evss/service_exception.rb', line 27

def messages_has_key?(key)
  @messages.any? { |m| m['key'].include? key.to_s }
end