Exception: Common::Exceptions::BackendServiceException

Inherits:
BaseError
  • Object
show all
Defined in:
lib/common/exceptions/backend_service_exception.rb

Overview

This will return a generic error, to customize you must define the minor code in the locales file and call this class from raise_error middleware.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseError

#log_to_sentry?, #sentry_type, #status_code

Constructor Details

#initialize(key = nil, response_values = {}, original_status = nil, original_body = nil) ⇒ BackendServiceException

rubocop:disable Metrics/ParameterLists



15
16
17
18
19
20
21
# File 'lib/common/exceptions/backend_service_exception.rb', line 15

def initialize(key = nil, response_values = {}, original_status = nil, original_body = nil)
  @response_values = response_values
  @key = key || 'VA900'
  @original_status = original_status
  @original_body = original_body
  validate_arguments!
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



12
13
14
# File 'lib/common/exceptions/backend_service_exception.rb', line 12

def key
  @key
end

#original_bodyObject (readonly)

Returns the value of attribute original_body.



12
13
14
# File 'lib/common/exceptions/backend_service_exception.rb', line 12

def original_body
  @original_body
end

#original_statusObject (readonly)

Returns the value of attribute original_status.



12
13
14
# File 'lib/common/exceptions/backend_service_exception.rb', line 12

def original_status
  @original_status
end

#response_valuesObject (readonly)

Returns the value of attribute response_values.



12
13
14
# File 'lib/common/exceptions/backend_service_exception.rb', line 12

def response_values
  @response_values
end

Instance Method Details

#errorsObject



30
31
32
# File 'lib/common/exceptions/backend_service_exception.rb', line 30

def errors
  Array(SerializableError.new(i18n_data.merge(render_overides)))
end

#messageObject

The message will be the actual backend service response from middleware, not the I18n version.



26
27
28
# File 'lib/common/exceptions/backend_service_exception.rb', line 26

def message
  "BackendServiceException: #{response_values.merge(code:)}"
end

#va900?Boolean Also known as: generic_error?

VA900 is characterized as a generic type of exception. See exceptions.en.yml for what JSON will render

Returns:

  • (Boolean)


35
36
37
# File 'lib/common/exceptions/backend_service_exception.rb', line 35

def va900?
  code == 'VA900'
end

#va900_hintObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/common/exceptions/backend_service_exception.rb', line 45

def va900_hint
  <<-MESSAGE.strip_heredoc
    Add the following to exceptions.en.yml
    #{response_values[:code]}:
      code: '#{response_values[:code]}'
      detail: '#{response_values[:detail]}'
      status: <http status code you want rendered (400, 422, etc)>
      source: ~
  MESSAGE
end

#va900_warningObject



41
42
43
# File 'lib/common/exceptions/backend_service_exception.rb', line 41

def va900_warning
  "Unmapped VA900 (Backend Response: { status: #{original_status}, message: #{original_body}) }"
end