class ElastomerClient::Client::Error

General error response from client requests.

Attributes

fatal[W]
error[R]

Returns the Elasticsearch error from the ‘response` or nil if the Error was not created with a response.

status[R]

Returns the status code from the ‘response` or nil if the Error was not created with a response.

Public Class Methods

fatal() click to toggle source

By default all client errors are fatal and indicate that a request should not be retried. Only a few errors are retryable.

# File lib/elastomer_client/client/errors.rb, line 67
def fatal
  return @fatal if defined? @fatal
  @fatal = true
end
Also aliased as: fatal?
fatal?()
Alias for: fatal
new(*args) click to toggle source

Construct a new Error from the given response object or a message String. If a response object is given, the error message will be extracted from the response body.

response - Faraday::Response object or a simple error message String

Calls superclass method
# File lib/elastomer_client/client/errors.rb, line 19
def initialize(*args)
  @status = nil
  @error = nil

  case args.first
  when Exception
    exception = args.shift
    super("#{exception.message} :: #{args.join(' ')}")
    set_backtrace exception.backtrace

  when Faraday::Response
    response = args.shift
    @status = response.status

    body = response.body
    @error = body["error"] if body.is_a?(Hash) && body.key?("error")

    message = @error || body.to_s
    super(message)

  else
    super(args.join(" "))
  end
end

Public Instance Methods

fatal?() click to toggle source

Indicates that the error is fatal. The request should not be tried again.

# File lib/elastomer_client/client/errors.rb, line 54
def fatal?
  self.class.fatal?
end
retry?() click to toggle source

The inverse of the ‘fatal?` method. A request can be retried if this method returns `true`.

# File lib/elastomer_client/client/errors.rb, line 60
def retry?
  !fatal?
end