Sha256: 63637bacbf974dbb1d8799448c02d3a7ae8c71b2352813304dae7dcb544268ab

Contents?: true

Size: 1.54 KB

Versions: 17

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Ledgers
    module TestLedger
      class 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_class
            raise NotImplementedError
          end

          def error_message # rubocop:disable Metrics/CyclomaticComplexity
            return error.message unless body

            parsed_body = JSON.parse(body)

            parsed_body.dig('fault', 'error')&.first&.fetch('message') ||
              parsed_body.dig('Fault', 'Error')&.first&.fetch('Message') ||
              parsed_body['error']
          end

          def detail # rubocop:disable Metrics/CyclomaticComplexity
            (body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('detail')) ||
              (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('Detail'))
          end

          def code # rubocop:disable Metrics/CyclomaticComplexity
            ((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

17 entries across 17 versions & 1 rubygems

Version Path
ledger_sync-2.6.0 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.5.0 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.4.4 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.3.1 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.2.3 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.2.1 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.2.0 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.0.2 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.0.1 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.0.0 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-2.0.0.pre.1 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-1.8.1 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-1.8.0 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-1.7.0 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-1.6.0 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-1.5.2 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
ledger_sync-1.5.1 lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb