From bca01b1a063213d8c4e72ace878741e396a03b45 Mon Sep 17 00:00:00 2001 From: Alexander Janot Date: Thu, 25 Jan 2024 11:00:06 +0100 Subject: [PATCH] Fix #133 - support influxdb v1.8 HTTP error response message An influxdb v1.8 HTTP error response message was not correctly transfered to ruby InfluxError message. In case of an InfuxError, the reason (except status code) was not traceable. How the fix works: - InfluxDB v1.8 and v2.x provide Error details in the json-rsp body - InfluxDB v2.x uses the `message` key for this - InfluxDB v1.8 uses the `error` key for this -> previously only `message` was supported -> now, in case `message` is empty, `error` is checked --- lib/influxdb2/client/influx_error.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/influxdb2/client/influx_error.rb b/lib/influxdb2/client/influx_error.rb index aad02a02..dde38738 100644 --- a/lib/influxdb2/client/influx_error.rb +++ b/lib/influxdb2/client/influx_error.rb @@ -32,7 +32,7 @@ def initialize(original = nil, message:, code:, reference:, retry_after:) def self.from_response(response) json = JSON.parse(response.body) - obj = new(message: json['message'] || '', code: response.code, reference: json['code'] || '', + obj = new(message: json['message'] || json['error'] || '', code: response.code, reference: json['code'] || '', retry_after: response['Retry-After'] || '') obj rescue JSON::ParserError