Class: BenefitsClaims::ServiceException

Inherits:
Object
  • Object
show all
Includes:
SentryLogging
Defined in:
lib/lighthouse/benefits_claims/service_exception.rb

Overview

Custom exception that maps Benefits Claims errors to error details defined in config/locales/exceptions.en.yml

Constant Summary collapse

ERROR_MAP =
{
  504 => Common::Exceptions::GatewayTimeout,
  503 => Common::Exceptions::ServiceUnavailable,
  502 => Common::Exceptions::BadGateway,
  500 => Common::Exceptions::ExternalServerInternalServerError,
  429 => Common::Exceptions::TooManyRequests,
  413 => Common::Exceptions::PayloadTooLarge,
  404 => Common::Exceptions::ResourceNotFound,
  403 => Common::Exceptions::Forbidden,
  401 => Common::Exceptions::Unauthorized,
  400 => Common::Exceptions::BadRequest
}.freeze

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Constructor Details

#initialize(e) ⇒ ServiceException

Returns a new instance of ServiceException.



24
25
26
27
28
29
# File 'lib/lighthouse/benefits_claims/service_exception.rb', line 24

def initialize(e)
  raise e unless e.key?(:status)

  status = e[:status].to_i
  raise_exception(status)
end

Instance Method Details

#raise_exception(status) ⇒ Object



31
32
33
34
35
# File 'lib/lighthouse/benefits_claims/service_exception.rb', line 31

def raise_exception(status)
  raise e unless ERROR_MAP.include?(status)

  raise ERROR_MAP[status]
end