Skip to content

Commit

Permalink
Adds error handling adjustments for synchronous endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
stiehlrod committed Apr 25, 2024
1 parent a2dc126 commit c682c7e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
28 changes: 23 additions & 5 deletions modules/claims_api/app/sidekiq/claims_api/service_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ def save_auto_claim!(auto_claim, status)
auto_claim.save!
end

def set_evss_response(auto_claim, error)
auto_claim.evss_response = []
error_messages = get_error_message(error)
error_messages.uniq.each do |error_message|
error_key = get_error_key(error_message)
error_text = get_error_text(error_message)
auto_claim.evss_response <<
{ 'key' => error_key,
'severity' => 'FATAL',
'text' => error_text }
end

auto_claim.status = ClaimsApi::AutoEstablishedClaim::ERRORED

save_auto_claim!(auto_claim, auto_claim.status)
end

def get_error_message(error)
if error.respond_to? :original_body
error.original_body
Expand All @@ -65,13 +82,13 @@ def get_error_message(error)
def get_error_key(error_message)
return error_message if error_message.is_a? String

error_message.dig(:messages, 0, :key) || error_message
error_message&.dig(:messages, 0, :key) || error_message&.dig(:key)
end

def get_error_text(error_message)
return error_message if error_message.is_a? String

error_message.dig(:messages, 0, :text) || error_message
error_message&.dig(:messages, 0, :text) || error_message&.dig(:text)
end

def get_error_status_code(error)
Expand All @@ -90,13 +107,14 @@ def get_original_status_code(error)
end
end

def will_retry?(error)
msg = if error.respond_to? :original_body
def will_retry?(auto_claim, error)
msg = if auto_claim.evss_response.present?
auto_claim.evss_response&.dig(0, 'text')
elsif error.respond_to? :original_body
get_error_key(error.original_body)
else
''
end

# If there is a match return false because we will not retry
NO_RETRY_ERROR_CODES.exclude?(msg)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,29 @@ def perform(claim_id) # rubocop:disable Metrics/MethodLength
# now upload to benefits documents
start_bd_uploader_job(auto_claim) if auto_claim.status != errored_state_value
rescue Faraday::ParsingError, Faraday::TimeoutError => e
set_errored_state_on_claim(auto_claim)
set_evss_response(auto_claim, e)
error_status = get_error_status_code(e)
error_message = get_error_message(e)

error_message = auto_claim.evss_response&.dig(0, 'text')
log_job_progress(claim_id,
"Docker container job errored #{e.class}: #{error_status} #{error_message}")

log_exception_to_sentry(e)

raise e
rescue ::Common::Exceptions::BackendServiceException => e
set_errored_state_on_claim(auto_claim)
set_evss_response(auto_claim, e)
error_message = get_error_message(e)

error_message = auto_claim.evss_response&.dig(0, 'text')
log_job_progress(claim_id,
"Docker container job errored #{e.class}: #{error_message}")
log_exception_to_sentry(e)
# if will_retry?
if will_retry?(e)
if will_retry?(auto_claim, e)
raise e
else # form526.submit.noRetryError OR form526.InProcess error retruned
{}
end
rescue => e
set_errored_state_on_claim(auto_claim)
set_evss_response(auto_claim, e)
set_evss_response(auto_claim, e) if auto_claim.evss_response.blank?
log_job_progress(claim_id,
"Docker container job errored #{e.class}: #{e&.detailed_message}")
log_exception_to_sentry(e)
Expand All @@ -78,21 +73,6 @@ def queue_flash_updater(flashes, auto_claim_id)
ClaimsApi::FlashUpdater.perform_async(flashes, auto_claim_id)
end

def set_evss_response(auto_claim, error)
error_message = get_error_message(error)
error_key = get_error_key(error_message)
error_text = get_error_text(error_message)

auto_claim.status = ClaimsApi::AutoEstablishedClaim::ERRORED
auto_claim.evss_response = [
{ 'key' => error_key,
'severity' => 'FATAL',
'text' => error_text }
]

save_auto_claim!(auto_claim, auto_claim.status)
end

def start_bd_uploader_job(auto_claim)
bd_service.perform_async(auto_claim.id)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def perform(claim_id, middle_initial, perform_async = true) # rubocop:disable Me
start_docker_container_job(auto_claim&.id, perform_async) if auto_claim.status != errored_state_value
rescue Faraday::ParsingError, Faraday::TimeoutError => e
set_errored_state_on_claim(auto_claim)
error_message = get_error_message(e)
error_message = auto_claim.evss_response&.dig(0, 'text') if auto_claim.evss_response.present?
set_evss_response(auto_claim, e)
error_status = get_error_status_code(e)

log_job_progress(claim_id,
Expand All @@ -63,7 +64,8 @@ def perform(claim_id, middle_initial, perform_async = true) # rubocop:disable Me
raise e
rescue ::Common::Exceptions::BackendServiceException => e
set_errored_state_on_claim(auto_claim)
error_message = get_error_message(e)
error_message = auto_claim.evss_response&.dig(0, 'text') if auto_claim.evss_response.present?
set_evss_response(auto_claim, e)
error_status = get_error_status_code(e)

log_job_progress(claim_id,
Expand Down

0 comments on commit c682c7e

Please sign in to comment.