Class: LedgerSync::Adaptors::QuickBooksOnline::Util::ErrorMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error:) ⇒ ErrorMatcher

Returns a new instance of ErrorMatcher.



11
12
13
14
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 11

def initialize(error:)
  @error = error
  @message = error.message.to_s
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 8

def error
  @error
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 8

def message
  @message
end

Instance Method Details

#bodyObject



16
17
18
19
20
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 16

def body
  error.response.body
rescue NoMethodError
  nil
end

#codeObject



38
39
40
41
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 38

def code
  ((body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('code')) ||
  (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('code'))).to_i
end

#detailObject



33
34
35
36
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 33

def detail
  (body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('detail')) ||
  (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('Detail'))
end

#error_klassObject

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 22

def error_klass
  raise NotImplementedError
end

#error_messageObject



26
27
28
29
30
31
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 26

def error_message
  (body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('message')) ||
  (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('Message')) ||
    (body && JSON.parse(body).dig('error')) ||
    error.message
end

#match?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 43

def match?
  raise NotImplementedError
end

#output_messageObject

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb', line 47

def output_message
  raise NotImplementedError
end