Class: Elastictastic::Middleware::RaiseServerErrors

Inherits:
Base
  • Object
show all
Defined in:
lib/elastictastic/middleware.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from TransportMethods

#delete, #get, #head, #post, #put

Constructor Details

This class inherits a constructor from Elastictastic::Middleware::Base

Instance Method Details

#request(method, path, body = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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