Class: LedgerSync::QuickBooksOnline::Util::OperationErrorParser

Inherits:
ErrorParser
  • Object
show all
Defined in:
lib/ledger_sync/quickbooks_online/util/operation_error_parser.rb

Defined Under Namespace

Classes: DuplicateNameMatcher, GenericMatcher, NotFoundMatcher, ValidationError

Constant Summary collapse

PARSERS =

! always keep GenericMatcher as last

[
  DuplicateNameMatcher,
  NotFoundMatcher,
  ValidationError,
  GenericMatcher
].freeze

Instance Attribute Summary collapse

Attributes inherited from ErrorParser

#error

Instance Method Summary collapse

Methods inherited from ErrorParser

#error_class

Constructor Details

#initialize(error:, operation: nil) ⇒ OperationErrorParser

Returns a new instance of OperationErrorParser.



77
78
79
80
# File 'lib/ledger_sync/quickbooks_online/util/operation_error_parser.rb', line 77

def initialize(error:, operation: nil)
  @operation = operation
  super(error: error)
end

Instance Attribute Details

#operationObject (readonly)

Returns the value of attribute operation.



75
76
77
# File 'lib/ledger_sync/quickbooks_online/util/operation_error_parser.rb', line 75

def operation
  @operation
end

Instance Method Details

#parseObject



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ledger_sync/quickbooks_online/util/operation_error_parser.rb', line 82

def parse
  PARSERS.map do |parser|
    matcher = parser.new(error: error)
    next unless matcher.match?

    return matcher.error_class.new(
      operation: operation,
      message: matcher.output_message,
      response: error
    )
  end
end