def handle_errors( response )
      raise ServerError, response if response.status >= 500

      if response.body.is_a?(Hash) && (error = response.body["error"])
        root_cause = Array(error["root_cause"]).first || error
        case root_cause["type"]
        when "index_not_found_exception"; raise IndexNotFoundError, response
        when "illegal_argument_exception"; raise IllegalArgument, response
        when "es_rejected_execution_exception"; raise RejectedExecutionError, response
        when *version_support.query_parse_exception; raise QueryParsingError, response
        end

        raise RequestError, response
      end

      response
    end
def handle_errors( response )
      raise ServerError, response if response.status >= 500

      if response.body.is_a?(Hash) && (error = response.body["error"])
        root_cause = Array(error["root_cause"]).first || error
        case root_cause["type"]
        when "index_not_found_exception"; raise IndexNotFoundError, response
        when "illegal_argument_exception"; raise IllegalArgument, response
        when "es_rejected_execution_exception"; raise RejectedExecutionError, response
        when *version_support.query_parse_exception; raise QueryParsingError, response
        end

        raise RequestError, response
      end

      response
    end
Internal: Inspect the Faraday::Response and raise an error if the status
 is in the 5XX range or if the response body contains an 'error' field.
 In the latter case, the value of the 'error' field becomes our exception
 message. In the absence of an 'error' field the response body is used
 as the exception message.

 The raised exception will contain the response object.

 response - The Faraday::Response object.

 Returns the response.
 Raises an Elastomer::Client::Error on 500 responses or responses
 containing and 'error' field.