Module: BGS::Exceptions::BGSErrors

Includes:
SentryLogging
Included in:
Service
Defined in:
lib/bgs/exceptions/bgs_errors.rb

Constant Summary collapse

MAX_ATTEMPTS =
3

Instance Method Summary collapse

Methods included from SentryLogging

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

Instance Method Details

#notify_of_service_exception(error, method, attempt = nil, status = :error) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bgs/exceptions/bgs_errors.rb', line 23

def notify_of_service_exception(error, method, attempt = nil, status = :error)
  msg = "Unable to #{method}: #{error.message}: try #{attempt} of #{MAX_ATTEMPTS}"
  context = { icn: @user[:icn] }
  tags = { team: 'vfs-ebenefits' }

  return log_message_to_sentry(msg, :warn, context, tags) if status == :warn

  log_oracle_errors!(error:)
  log_exception_to_sentry(error, context, tags)
  raise_backend_exception('BGS_686c_SERVICE_403', self.class, error)
end

#raise_backend_exception(key, source, error) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/bgs/exceptions/bgs_errors.rb', line 35

def raise_backend_exception(key, source, error)
  exception = BGS::ServiceException.new(
    key,
    { source: source.to_s },
    403,
    error.message
  )

  raise exception
end

#with_multiple_attempts_enabledObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bgs/exceptions/bgs_errors.rb', line 10

def with_multiple_attempts_enabled
  attempt ||= 0
  yield
rescue => e
  attempt += 1
  if attempt < MAX_ATTEMPTS
    notify_of_service_exception(e, __method__.to_s, attempt, :warn)
    retry
  end

  notify_of_service_exception(e, __method__.to_s)
end