lib/elastic/transport/transport/base.rb in elastic-transport-8.2.3 vs lib/elastic/transport/transport/base.rb in elastic-transport-8.2.4

- old
+ new

@@ -344,13 +344,20 @@ # Log the failure only when `ignore` doesn't match the response status log_fatal("[#{response.status}] #{response.body}") unless ignore.include?(response.status.to_i) __raise_transport_error response unless ignore.include?(response.status.to_i) end - json = serializer.load(response.body) if response.body && - !response.body.empty? && - response.headers && - response.headers["content-type"] =~ /json/ + if response.body && + !response.body.empty? && + response.headers && + response.headers["content-type"] =~ /json/ + + # Prevent Float value from automatically becoming BigDecimal when using Oj + load_options = {} + load_options[:mode] = :compat if ::MultiJson.adapter.to_s == "MultiJson::Adapters::Oj" + + json = serializer.load(response.body, load_options) + end took = (json['took'] ? sprintf('%.3fs', json['took'] / 1000.0) : 'n/a') rescue 'n/a' __log_response(method, path, params, body, url, response, json, took, duration) unless ignore.include?(response.status.to_i) __trace(method, path, params, connection_headers(connection), body, url, response, nil, 'N/A', duration) if tracer log_warn(response.headers['warning']) if response.headers&.[]('warning')