Class: Lighthouse::DirectDeposit::ErrorParser

Inherits:
Object
  • Object
show all
Defined in:
lib/lighthouse/direct_deposit/error_parser.rb

Class Method Summary collapse

Class Method Details

.data_sourceObject



72
73
74
# File 'lib/lighthouse/direct_deposit/error_parser.rb', line 72

def self.data_source
  'Lighthouse Direct Deposit'
end

.parse(response) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lighthouse/direct_deposit/error_parser.rb', line 8

def self.parse(response)
  body = parse_body(response[:body])
  detail = parse_detail(body)
  status = parse_status(response[:status], detail)

  errors = [
    {
      title: parse_title(body),
      detail:,
      code: parse_code(detail),
      source: data_source
    }
  ]

  Lighthouse::DirectDeposit::ErrorResponse.new(status, errors)
end

.parse_body(body) ⇒ Object



33
34
35
# File 'lib/lighthouse/direct_deposit/error_parser.rb', line 33

def self.parse_body(body)
  body.to_hash.with_indifferent_access
end

.parse_code(detail) ⇒ Object

rubocop:disable Metrics/MethodLength



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/lighthouse/direct_deposit/error_parser.rb', line 46

def self.parse_code(detail) # rubocop:disable Metrics/MethodLength
  return 'cnp.payment.api.rate.limit.exceeded' if detail.include? 'API rate limit exceeded'
  return 'cnp.payment.api.gateway.timeout' if detail.include? 'Did not receive a timely response'
  return 'cnp.payment.invalid.authentication.creds' if detail.include? 'Invalid authentication credentials'
  return 'cnp.payment.invalid.token' if detail.include? 'Invalid token'
  return 'cnp.payment.invalid.scopes' if detail.include? 'scopes are not configured'
  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.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.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.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.potential.fraud' if detail.include? 'GUIE50041'
  return 'cnp.payment.unspecified.error' if detail.include? 'GUIE50022'

  'cnp.payment.generic.error'
end

.parse_detail(body) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/lighthouse/direct_deposit/error_parser.rb', line 37

def self.parse_detail(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')

  messages.compact.join(': ')
end

.parse_status(status, _detail) ⇒ Object



25
26
27
# File 'lib/lighthouse/direct_deposit/error_parser.rb', line 25

def self.parse_status(status, _detail)
  status
end

.parse_title(body) ⇒ Object



29
30
31
# File 'lib/lighthouse/direct_deposit/error_parser.rb', line 29

def self.parse_title(body)
  body[:error] || body[:title] || status_message_from(body[:status]) || 'Unknown error'
end

.status_message_from(code) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/lighthouse/direct_deposit/error_parser.rb', line 76

def self.status_message_from(code)
  case code
  when 401
    'Not Authorized'
  when 403
    'Forbidden'
  when 413
    'Payload too large'
  when 429
    'Too many requests'
  end
end