Sha256: 5001adc9f818f95fa85f2ce49003cb25327b8626c2934329498e405f3c552e8f

Contents?: true

Size: 1.45 KB

Versions: 12

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Esse
  class Transport
    require_relative './transport/aliases'
    require_relative './transport/health'
    require_relative './transport/indices'
    require_relative './transport/search'
    require_relative './transport/documents'

    extend Forwardable

    def_delegators :@cluster, :client, :throw_error_when_readonly!

    attr_reader :cluster

    def initialize(cluster)
      @cluster = cluster
    end

    # Elasticsearch::Transport was renamed to Elastic::Transport in 8.0
    # This lib should support both versions that's why we are wrapping up the transport
    # errors to local errors.
    #
    # We are not only coercing exceptions but also the response body. Elasticsearch-ruby >= 8.0 returns
    # the response wrapped in a Elasticsearch::API::Response::Response object. We are unwrapping it
    # to keep the same interface. But we may want to coerce it to some internal object in the future.
    def coerce_exception
      resp = yield
      if resp.class.name.start_with?('Elasticsearch::API::Response')
        resp = resp.body
      end
      resp
    rescue => exception
      name = Hstring.new(exception.class.name)
      if /^(Elasticsearch|Elastic|OpenSearch)?::Transport::Transport::Errors/.match?(name.value) && \
          (exception_class = Esse::Transport::ERRORS[name.demodulize.value])
        raise exception_class.new(exception.message)
      else
        raise exception
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
esse-0.4.0.rc2 lib/esse/transport.rb
esse-0.4.0.rc1 lib/esse/transport.rb
esse-0.3.5 lib/esse/transport.rb
esse-0.3.4 lib/esse/transport.rb
esse-0.3.3 lib/esse/transport.rb
esse-0.3.2 lib/esse/transport.rb
esse-0.3.1 lib/esse/transport.rb
esse-0.3.0 lib/esse/transport.rb
esse-0.2.6 lib/esse/transport.rb
esse-0.2.5 lib/esse/transport.rb
esse-0.2.4 lib/esse/transport.rb
esse-0.2.3 lib/esse/transport.rb