Exception: InfluxDB2::InfluxError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/influxdb2/client/influx_error.rb

Overview

InfluxError that is raised during HTTP communication.

Constant Summary collapse

HTTP_ERRORS =
[
  EOFError,
  Errno::ECONNREFUSED,
  Errno::ECONNRESET,
  Errno::EINVAL,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  Timeout::Error
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original = nil, message:, code:, reference:, retry_after:) ⇒ InfluxError

Returns a new instance of InfluxError.



24
25
26
27
28
29
30
31
# File 'lib/influxdb2/client/influx_error.rb', line 24

def initialize(original = nil, message:, code:, reference:, retry_after:)
  super(message)

  @code = code
  @reference = reference
  @retry_after = retry_after
  @original = original
end

Instance Attribute Details

#codeObject (readonly)

HTTP status code



16
17
18
# File 'lib/influxdb2/client/influx_error.rb', line 16

def code
  @code
end

#originalObject (readonly)

original error



22
23
24
# File 'lib/influxdb2/client/influx_error.rb', line 22

def original
  @original
end

#referenceObject (readonly)

Reference code unique to the error type



18
19
20
# File 'lib/influxdb2/client/influx_error.rb', line 18

def reference
  @reference
end

#retry_afterObject (readonly)

The Retry-After header describes when to try the request again.



20
21
22
# File 'lib/influxdb2/client/influx_error.rb', line 20

def retry_after
  @retry_after
end

Class Method Details

.from_error(error) ⇒ Object



48
49
50
51
# File 'lib/influxdb2/client/influx_error.rb', line 48

def self.from_error(error)
  obj = new(error, message: error.message, code: '', reference: '', retry_after: '')
  obj
end

.from_message(message) ⇒ Object



43
44
45
46
# File 'lib/influxdb2/client/influx_error.rb', line 43

def self.from_message(message)
  obj = new(message: message, code: '', reference: '', retry_after: '')
  obj
end

.from_response(response) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/influxdb2/client/influx_error.rb', line 33

def self.from_response(response)
  json = JSON.parse(response.body)
  obj = new(message: json['message'] || json['error'] || '', code: response.code, reference: json['code'] || '',
            retry_after: response['Retry-After'] || '')
  obj
rescue JSON::ParserError
  new(message: response.body || '', code: response.code, reference: '',
      retry_after: response['Retry-After'] || '')
end