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

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_sync/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.



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

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

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

Instance Method Details

#bodyObject



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

def body
  @body ||= error.response.body
rescue NoMethodError
  nil
end

#codeObject



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

def code
  return if body.blank?

  fault&.fetch('code') ||
    fault&.fetch('code').to_i
end

#detailObject



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

def detail
  return if body.blank?

  fault&.fetch('detail') ||
    fault&.fetch('Detail')
end

#error_classObject

Raises:

  • (NotImplementedError)


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

def error_class
  raise NotImplementedError
end

#error_messageObject



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

def error_message
  return error.message unless body

  fault&.fetch('message', nil) ||
    fault&.fetch('Message', nil) ||
    parsed_body['error']
end

#match?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

def match?
  raise NotImplementedError
end

#output_messageObject

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/ledger_sync/quickbooks_online/util/error_matcher.rb', line 55

def output_message
  raise NotImplementedError
end

#parsed_bodyObject



51
52
53
# File 'lib/ledger_sync/quickbooks_online/util/error_matcher.rb', line 51

def parsed_body
  @parsed_body ||= JSON.parse(body)
end