Skip to content

Commit

Permalink
Add error parsing for unhandled responses and update logic (#12998)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpharrison authored Jun 15, 2023
1 parent b286a3d commit 6af6591
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 18 deletions.
30 changes: 13 additions & 17 deletions lib/lighthouse/direct_deposit/error_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ def self.parse_title(body)
end

def self.parse_detail(body)
return parse_first_error_code(body) if error_codes?(body)
messages = []
messages.push(body[:error_codes][0][:error_code]) if body[:error_codes].present?
messages.push(body[:error_codes][0][:detail]) if body[:error_codes].present?
messages.push(body[:error_description] || body[:error] || body[:detail] || body[:message] || 'Unknown error')

body[:error_description] || body[:error] || body[:detail] || body[:message] || 'Unknown error'
messages.compact.join(': ')
end

def self.parse_code(detail)
Expand All @@ -40,12 +43,17 @@ def self.parse_code(detail)
return 'cnp.payment.icn.not.found' if detail.include? 'No data found for ICN'
return 'cnp.payment.icn.invalid' if detail.include? 'getDirectDeposit.icn size'
return 'cnp.payment.account.number.invalid' if detail.include? 'payment.accountNumber.invalid'
return 'cnp.payment.routing.number.invalid' if detail.include? 'payment.accountRoutingNumber.invalid'
return 'cnp.payment.account.type.invalid' if detail.include? 'payment.accountType.invalid'
return 'cnp.payment.account.number.fraud' if detail.include? 'Flashes on record'
return 'cnp.payment.routing.number.invalid.checksum' if detail.include? 'accountRoutingNumber.invalidCheckSum'
return 'cnp.payment.restriction.indicators.present' if detail.include? 'restriction.indicators.present'
return 'cnp.payment.routing.number.invalid' if detail.include? 'payment.accountRoutingNumber.invalid'
return 'cnp.payment.routing.number.fraud' if detail.include? 'Routing number related to potential fraud'
return 'cnp.payment.accounting.number.fraud' if detail.include? 'Flashes on record'
return 'cnp.payment.restriction.indicators.present' if detail.include? 'restriction.indicators.present'
return 'cnp.payment.day.phone.number.invalid' if detail.include? 'Day phone number is invalid'
return 'cnp.payment.day.area.number.invalid' if detail.include? 'Day area number is invalid'
return 'cnp.payment.night.phone.number.invalid' if detail.include? 'Night phone number is invalid'
return 'cnp.payment.night.area.number.invalid' if detail.include? 'Night area number is invalid'
return 'cnp.payment.mailing.address.invalid' if detail.include? 'field not entered for mailing address update'
return 'cnp.payment.unspecified.error' if detail.include? 'GUIE50022'

'cnp.payment.generic.error'
Expand All @@ -55,18 +63,6 @@ def self.data_source
'Lighthouse Direct Deposit'
end

def self.parse_first_error_code(body)
body[:error_codes][0][:error_code]
end

def self.parse_first_error_detail(body)
body[:error_codes][0][:detail]
end

def self.error_codes?(body)
body[:error_codes].present?
end

def self.status_message_from(code)
case code
when 401
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,55 @@

expect(e).not_to be_nil
expect(e['title']).to eq('Bad Request')
expect(e['code']).to eq('cnp.payment.accounting.number.fraud')
expect(e['code']).to eq('cnp.payment.account.number.fraud')
expect(e['source']).to eq('Lighthouse Direct Deposit')
end

it 'returns a day phone number error' do
VCR.use_cassette('lighthouse/direct_deposit/update/400_invalid_day_phone_number') do
put(:update, params:)
end

expect(response).to have_http_status(:bad_request)

json = JSON.parse(response.body)
e = json['errors'].first

expect(e).not_to be_nil
expect(e['title']).to eq('Bad Request')
expect(e['code']).to eq('cnp.payment.day.phone.number.invalid')
expect(e['source']).to eq('Lighthouse Direct Deposit')
end

it 'returns an mailing address error' do
VCR.use_cassette('lighthouse/direct_deposit/update/400_invalid_mailing_address') do
put(:update, params:)
end

expect(response).to have_http_status(:bad_request)

json = JSON.parse(response.body)
e = json['errors'].first

expect(e).not_to be_nil
expect(e['title']).to eq('Bad Request')
expect(e['code']).to eq('cnp.payment.mailing.address.invalid')
expect(e['source']).to eq('Lighthouse Direct Deposit')
end

it 'returns a routing number checksum error' do
VCR.use_cassette('lighthouse/direct_deposit/update/400_routing_number_checksum') do
put(:update, params:)
end

expect(response).to have_http_status(:bad_request)

json = JSON.parse(response.body)
e = json['errors'].first

expect(e).not_to be_nil
expect(e['title']).to eq('Bad Request')
expect(e['code']).to eq('cnp.payment.routing.number.invalid.checksum')
expect(e['source']).to eq('Lighthouse Direct Deposit')
end
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6af6591

Please sign in to comment.