Sha256: 386691e1fa7b301011f933641ea60cbcc68f251cadd8b81b3b80a1d41df5eef5

Contents?: true

Size: 1.32 KB

Versions: 13

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

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

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

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

        def error_class
          raise NotImplementedError
        end

        def error_message
          return error.message unless body

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

        def detail
          return if body.blank?

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

        def code
          return if body.blank?

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

        def match?
          raise NotImplementedError
        end

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

        def output_message
          raise NotImplementedError
        end

        private

        def fault
          parsed_body.dig('fault', 'error')&.first ||
            parsed_body.dig('Fault', 'Error')&.first
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ledger_sync-quickbooks_online-2.0.0 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-1.0.1 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-1.0.0 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.4.0 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.3.1 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.3.0 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.2.6 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.2.5 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.2.4 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.2.2 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.2.1 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.2.0 lib/ledger_sync/quickbooks_online/util/error_matcher.rb
ledger_sync-quickbooks_online-0.1.1 lib/ledger_sync/quickbooks_online/util/error_matcher.rb