From c682c7e01f26500b8f6923bc650f7894069d40a6 Mon Sep 17 00:00:00 2001 From: Jennica Stiehl <25069483+stiehlrod@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:12:36 -0600 Subject: [PATCH] Adds error handling adjustments for synchronous endpoint. --- .../app/sidekiq/claims_api/service_base.rb | 28 +++++++++++++++---- ...ty_compensation_docker_container_upload.rb | 28 +++---------------- .../disability_compensation_pdf_generator.rb | 6 ++-- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/modules/claims_api/app/sidekiq/claims_api/service_base.rb b/modules/claims_api/app/sidekiq/claims_api/service_base.rb index fe6087095b6..0dd2bcaa841 100644 --- a/modules/claims_api/app/sidekiq/claims_api/service_base.rb +++ b/modules/claims_api/app/sidekiq/claims_api/service_base.rb @@ -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 @@ -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) @@ -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 diff --git a/modules/claims_api/app/sidekiq/claims_api/v2/disability_compensation_docker_container_upload.rb b/modules/claims_api/app/sidekiq/claims_api/v2/disability_compensation_docker_container_upload.rb index 920d5fddf8a..c2718cfbfd6 100644 --- a/modules/claims_api/app/sidekiq/claims_api/v2/disability_compensation_docker_container_upload.rb +++ b/modules/claims_api/app/sidekiq/claims_api/v2/disability_compensation_docker_container_upload.rb @@ -35,11 +35,9 @@ 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}") @@ -47,22 +45,19 @@ def perform(claim_id) # rubocop:disable Metrics/MethodLength 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) @@ -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 diff --git a/modules/claims_api/app/sidekiq/claims_api/v2/disability_compensation_pdf_generator.rb b/modules/claims_api/app/sidekiq/claims_api/v2/disability_compensation_pdf_generator.rb index a2fa928f19f..efb3ef8f8e3 100644 --- a/modules/claims_api/app/sidekiq/claims_api/v2/disability_compensation_pdf_generator.rb +++ b/modules/claims_api/app/sidekiq/claims_api/v2/disability_compensation_pdf_generator.rb @@ -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, @@ -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,