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

- old
+ new

@@ -19,11 +19,11 @@ # @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure # # @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/ def create_index(suffix: index_version, **options) create_index!(suffix: suffix, **options) - rescue Elasticsearch::Transport::Transport::Errors::BadRequest + rescue ServerError { 'errors' => true } end # Creates index and applies mappings and settings. # @@ -37,11 +37,11 @@ # to wait for before the operation returns. # @option arguments [Time] :timeout Explicit operation timeout # @option arguments [Time] :master_timeout Specify timeout for connection to master # @option arguments [Hash] :headers Custom HTTP headers # @option arguments [Hash] :body The configuration for the index (`settings` and `mappings`) - # @raise [Elasticsearch::Transport::Transport::Errors::NotFound] when index already exists + # @raise [Esse::Backend::NotFoundError] when index already exists # @return [Hash] the elasticsearch response # # @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/ def create_index!(suffix: index_version, **options) options = DEFAULT_OPTIONS.merge(options) @@ -52,11 +52,11 @@ definition[:aliases] = { index_name => {} } end Esse::Events.instrument('elasticsearch.create_index') do |payload| payload[:request] = opts = options.merge(index: name, body: definition) - payload[:response] = response = client.indices.create(**opts) - cluster.wait_for_status! if response + payload[:response] = response = coerce_exception { client.indices.create(**opts) } + coerce_exception { cluster.wait_for_status! } if response response end end end