Class: ElastomerClient::Client::Error
- Defined in:
- lib/elastomer_client/client/errors.rb
Overview
General error response from client requests.
Class Attribute Summary collapse
-
.fatal ⇒ Object
(also: fatal?)
By default all client errors are fatal and indicate that a request should not be retried.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the Elasticsearch error from the ‘response` or nil if the Error was not created with a response.
-
#status ⇒ Object
readonly
Returns the status code from the ‘response` or nil if the Error was not created with a response.
Instance Method Summary collapse
-
#fatal? ⇒ Boolean
Indicates that the error is fatal.
-
#initialize(*args) ⇒ Error
constructor
Construct a new Error from the given response object or a message String.
-
#retry? ⇒ Boolean
The inverse of the ‘fatal?` method.
Constructor Details
#initialize(*args) ⇒ Error
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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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.} :: #{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") = @error || body.to_s super() else super(args.join(" ")) end end |
Class Attribute Details
.fatal ⇒ Object Also known as: fatal?
By default all client errors are fatal and indicate that a request should not be retried. Only a few errors are retryable.
67 68 69 70 |
# File 'lib/elastomer_client/client/errors.rb', line 67 def fatal return @fatal if defined? @fatal @fatal = true end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the Elasticsearch error from the ‘response` or nil if the Error was not created with a response.
50 51 52 |
# File 'lib/elastomer_client/client/errors.rb', line 50 def error @error end |
#status ⇒ Object (readonly)
Returns the status code from the ‘response` or nil if the Error was not created with a response.
46 47 48 |
# File 'lib/elastomer_client/client/errors.rb', line 46 def status @status end |
Instance Method Details
#fatal? ⇒ Boolean
Indicates that the error is fatal. The request should not be tried again.
54 55 56 |
# File 'lib/elastomer_client/client/errors.rb', line 54 def fatal? self.class.fatal? end |
#retry? ⇒ Boolean
The inverse of the ‘fatal?` method. A request can be retried if this method returns `true`.
60 61 62 |
# File 'lib/elastomer_client/client/errors.rb', line 60 def retry? !fatal? end |