From 41a7bf69f50d01f3de4b4596cb400188fb861e7b Mon Sep 17 00:00:00 2001 From: Alexander Janot Date: Thu, 25 Jan 2024 11:00:06 +0100 Subject: [PATCH] fix: support influxdb v1.8 HTTP error response message An influxdb v1.8 HTTP error response message was not correctly transfered to the ruby InfluxError message. In case of an InfuxError, the reason (error message) 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 Refs: #133 --- 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