From 53df47b1a7e6bb949590dd07a19dceb3c2a5fd09 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 --- CHANGELOG.md | 3 +++ lib/influxdb2/client/influx_error.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0830c2b..848c0f4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 3.1.0 [unreleased] +### Bug Fixes +1. [#134](https://github.com/influxdata/influxdb-client-ruby/pull/134): Support influxdb v1.8 HTTP error response message. Prior to this change, in case of an HTTP error response (influxDB v1.8) the InfluxError had empty message. + ## 3.0.0 [2023-12-05] ### Bug Fixes 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