Skip to content

Commit

Permalink
Updates disability compensation controller to not look for the messag…
Browse files Browse the repository at this point in the history
…es key since custom error will handle that and claims controller also does not look for that in its formatter
  • Loading branch information
rockwellwindsor-va committed Apr 16, 2024
1 parent 63a9253 commit cc38a17
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def validate_form_526
track_526_validation_errors(error_details)
raise ::Common::Exceptions::UnprocessableEntity.new(errors: format_526_errors(error_details))
rescue ::Common::Exceptions::BackendServiceException => e
error_details = e&.original_body&.[](:messages)
raise ::Common::Exceptions::UnprocessableEntity.new(errors: format_526_errors(error_details))
raise ::Common::Exceptions::UnprocessableEntity.new(errors: format_526_errors(e.original_body))
rescue ::Common::Exceptions::GatewayTimeout,
::Timeout::Error,
::Faraday::TimeoutError,
Expand Down
4 changes: 1 addition & 3 deletions modules/claims_api/lib/custom_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

module ClaimsApi
class CustomError
def initialize(error, claim, method)
def initialize(error)
@error = error
@claim = claim
@method = method
end

def build_error
Expand Down
12 changes: 6 additions & 6 deletions modules/claims_api/lib/evss_service/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def submit(claim, data)
log_outcome_for_claims_api('submit', 'success', resp, claim)
resp # return is for v1 Sidekiq worker
rescue => e
error_handler(e, claim, 'submit')
error_handler(e)
end
end

Expand All @@ -43,7 +43,7 @@ def validate(claim, data)
detail = e.respond_to?(:original_body) ? e.original_body : e
log_outcome_for_claims_api('validate', 'error', detail, claim)

error_handler(e, claim, 'validate')
error_handler(e)
end
end

Expand Down Expand Up @@ -90,12 +90,12 @@ def log_outcome_for_claims_api(action, status, response, claim)
detail: "EVSS DOCKER CONTAINER #{action} #{status}: #{response}", claim: claim&.id)
end

def custom_error(error, claim, method)
ClaimsApi::CustomError.new(error, claim, method)
def custom_error(error)
ClaimsApi::CustomError.new(error)
end

def error_handler(error, claim, method)
custom_error(error, claim, method).build_error
def error_handler(error)
custom_error(error).build_error
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# spec/controllers/disability_compensation_controller_spec.rb

require 'rails_helper'

RSpec.describe ClaimsApi::V1::Forms::DisabilityCompensationController, type: :controller do
describe '#format_526_errors' do
it 'formats errors correctly' do
error = [
{
key: 'header.va_eauth_birlsfilenumber.Invalid',
severity: 'ERROR',
text: 'Size must be between 8 and 9'
}
]

formatted_error = subject.send(:format_526_errors, error)

expect(formatted_error).to match_array([
{ status: 422, detail: "#{error[0][:key]}, #{error[0][:text]}",
source: error[0][:key] }
])
end
end
end
4 changes: 2 additions & 2 deletions modules/claims_api/spec/sidekiq/claim_custom_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
)
end

let(:backend_error_submit) { ClaimsApi::CustomError.new(backend_error, claim, 'submit') }
let(:backend_error_submit) { ClaimsApi::CustomError.new(backend_error) }

it 'correctly set the key as the string value from the error message' do
backend_error_submit.build_error
Expand Down Expand Up @@ -78,7 +78,7 @@
)
end

let(:backend_error_submit) { ClaimsApi::CustomError.new(backend_error, claim, 'submit') }
let(:backend_error_submit) { ClaimsApi::CustomError.new(backend_error) }

it 'sets the evss_response to the original body error message' do
backend_error_submit.build_error
Expand Down

0 comments on commit cc38a17

Please sign in to comment.