From 05cf01be3b6587e1e861b4ca616cd1416f2abc9d Mon Sep 17 00:00:00 2001 From: Rory Johnston Date: Mon, 6 Jan 2025 13:48:49 +0000 Subject: [PATCH] (SUP-5232) Added error handling to JSON conversion of metrics --- files/pe_metrics.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/files/pe_metrics.rb b/files/pe_metrics.rb index a61c37c9..fc0c1f3e 100644 --- a/files/pe_metrics.rb +++ b/files/pe_metrics.rb @@ -79,7 +79,16 @@ def post_endpoint(url, body) end def retrieve_additional_metrics(url, _metrics_type, metrics) - metrics_output = post_endpoint(url, metrics.to_json) + begin + json_data = metrics.to_json + rescue StandardError => e + STDERR.puts 'Failed to convert metrics to JSON.' + STDERR.puts "Error: #{e.message}" + STDERR.puts e.backtrace + return [] + end + + metrics_output = post_endpoint(url, json_data) return [] if metrics_output.empty? # For a status other than 200 or 404, add the HTTP code to the error array