Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
LG-3280 Adding ConversationId and Reference to LexisNexis error loggi…
Browse files Browse the repository at this point in the history
…ng… (#16)

LG-3280 Adding ConversationId and Reference to response class and error logging to allow easier follow up on proofing failures.
  • Loading branch information
amathews-fs authored Aug 19, 2020
1 parent 816985b commit 1bef47e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
12 changes: 11 additions & 1 deletion lib/lexisnexis/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def verification_status
@verification_status ||= response_body.dig('Status', 'TransactionStatus')
end

def conversation_id
@conversation_id ||= response_body.dig('Status', 'ConversationId')
end

def reference
@reference ||= response_body.dig('Status', 'Reference')
end

# @api private
def response_body
@response_body ||= JSON.parse(response.body)
Expand All @@ -51,7 +59,9 @@ def handle_verification_transaction_error

error_code = response_body.dig('Status', 'TransactionReasonCode', 'Code')
error_information = response_body.fetch('Information', {}).to_json
message = "Response error with code '#{error_code}': #{error_information}"
tracking_ids = "(LN ConversationId: #{conversation_id}; Reference: #{reference}) "

message = "#{tracking_ids} Response error with code '#{error_code}': #{error_information}"
raise VerificationTransactionError, message
end
end
Expand Down
8 changes: 6 additions & 2 deletions lib/lexisnexis/verification_error_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ def parsed_errors

def base_error_message
error_code = body.dig('Status', 'TransactionReasonCode', 'Code')
return 'Verification failed without a reason code' if error_code.nil?
conversation_id = body.dig('Status', 'ConversationId')
reference = body.dig('Status', 'Reference')
tracking_ids = "(LN ConversationId: #{conversation_id}; Reference: #{reference}) "

"Verification failed with code: '#{error_code}'"
return "#{tracking_ids} Verification failed without a reason code" if error_code.nil?

"#{tracking_ids} Verification failed with code: '#{error_code}'"
end

def product_error_messages
Expand Down
2 changes: 1 addition & 1 deletion lib/lexisnexis/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module LexisNexis
VERSION = '2.2.0'.freeze
VERSION = '2.3.0'.freeze
end
6 changes: 3 additions & 3 deletions spec/lib/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
end

expect(error).to be_a(LexisNexis::Response::VerificationTransactionError)
expect(error.message).to include(
"Response error with code 'invalid_transaction_initiate'"
)
expect(error.message).to include("5556787618334595970")
expect(error.message).to include("1234-abcd")
expect(error.message).to include("invalid_transaction_initiate")
expect(error.message).to include(JSON.parse(response_body)['Information'].to_json)
end
end
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/verification_error_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
it 'should return an array of errors from the response' do
errors = subject.parsed_errors

expect(errors[:base]).to eq(
"Verification failed with code: 'total.scoring.model.verification.fail'"
)
expect(errors[:base]).to include("total.scoring.model.verification.fail")
expect(errors[:base]).to include("31000123456789")
expect(errors[:base]).to include("1234-abcd")

expect(errors[:Discovery]).to eq(nil) # This should be absent since it passed
expect(errors[:SomeOtherProduct]).to eq(response_body['Products'][1].to_json)
expect(errors[:InstantVerify]).to eq(response_body['Products'][2].to_json)
Expand Down
1 change: 1 addition & 0 deletions spec/support/fixtures/instant_verify/error_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"TransactionReasonCode": {
"Code": "invalid_transaction_initiate"
},
"Reference": "1234-abcd",
"ServerInfo": "ALANARABA01-W7D"
},
"Information": [
Expand Down
1 change: 1 addition & 0 deletions spec/support/fixtures/instant_verify/failed_response.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"Status": {
"ConversationId": "31000123456789",
"RequestId": "13936762",
"TransactionStatus": "failed",
"TransactionReasonCode": {
Expand Down

0 comments on commit 1bef47e

Please sign in to comment.