lib/esse/backend/index.rb in esse-0.2.0 vs lib/esse/backend/index.rb in esse-0.2.2

- old
+ new

@@ -18,37 +18,39 @@ extend Forwardable NAMING = %i[index_version].freeze DEFINITION = %i[settings_hash mappings_hash].freeze + DOCUMENTS = %i[each_serialized_batch].freeze - def_delegators :@index, :type_hash, *(NAMING + DEFINITION) + def_delegators :@index, :index_name, :cluster, :repo_hash, :bulk_wait_interval, *(NAMING + DEFINITION + DOCUMENTS) + def_delegators :cluster, :document_type?, :client def initialize(index) @index = index end protected - def index_name(suffix: nil) - suffix = Hstring.new(suffix).underscore.presence - return @index.index_name unless suffix - - [@index.index_name, suffix].join('_') - end - def build_real_index_name(suffix = nil) suffix = Hstring.new(suffix).underscore.presence || index_version || Esse.timestamp index_name(suffix: suffix) end - def client - cluster.client - end - - def cluster - @index.cluster + # 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. + def coerce_exception + yield + rescue => exception + name = Hstring.new(exception.class.name) + if /^(Elasticsearch|Elastic|OpenSearch)?::Transport::Transport::Errors/.match?(name.value) && \ + (exception_class = ERRORS[name.demodulize.value]) + raise exception_class.new(exception.message) + else + raise exception + end end end end end