class Elastictastic::Middleware::RaiseServerErrors

Public Instance Methods

request(method, path, body = nil) click to toggle source
Calls superclass method Elastictastic::Middleware::Base#request
# File lib/elastictastic/middleware.rb, line 56
def request(method, path, body = nil)
  super.tap do |response|
    if method != :head
      if response.body.nil?
        raise Elastictastic::ServerError::ServerError,
          "No body in ElasticSearch response with status #{env[:status]}"
      elsif response.body['error']
        raise_error(response.body['error'], response.body['status'])
      elsif response.body['_shards'] && response.body['_shards']['failures']
        raise_error(
          response.body['_shards']['failures'].first['reason'], response.body['status'])
      end
    end
  end
end

Private Instance Methods

raise_error(server_message, status) click to toggle source
# File lib/elastictastic/middleware.rb, line 74
def raise_error(server_message, status)
  ::Kernel.raise(Elastictastic::ServerError[server_message, status])
end