Module: EtFakeCcd::ForcedErrorHandling

Extended by:
ActiveSupport::Concern
Included in:
Service::AuthApp, Service::AuthenticationWebApp, Service::DataStoreApp, Service::DocumentStoreApp, Service::EcmApp, Service::SidamApp
Defined in:
lib/et_fake_ccd/forced_error_handling.rb

Instance Method Summary collapse

Instance Method Details

#with_forced_error_handling(r, stage:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/et_fake_ccd/forced_error_handling.rb', line 6

def with_forced_error_handling(r, stage:)
  request_id = r.headers['request_id']
  RequestStoreService.store "#{stage}-#{request_id}" unless request_id.nil?
  count = request_id.nil? ? 1 : RequestStoreService.count("#{stage}-#{request_id}")
  specs = JSON.parse(r.headers['force_failures'] || '{}')
  spec = specs.fetch("#{stage}_stage", [])
  response_code = spec[count - 1].to_i
  if response_code.zero?
    yield
  else
    r.halt response_code
  end
end