Sha256: 68bc45fbf8ee37c937b2c8956416cd6508c81ec3b9bffe99206bd0eb222a3f7c

Contents?: true

Size: 1.4 KB

Versions: 12

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module Util
        class ErrorMatcher
          attr_reader :error,
                      :message

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

          def body
            error.response.body
          rescue NoMethodError
            nil
          end

          def error_klass
            raise NotImplementedError
          end

          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

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

          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

          def match?
            raise NotImplementedError
          end

          def output_message
            raise NotImplementedError
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ledger_sync-1.3.4 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.3.3 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.1.3 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.1.2 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.1.1 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.0.10 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.0.9 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.0.3 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.0.2 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
ledger_sync-1.0.0 lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb