Skip to content

Commit ffd12b7

Browse files
authored
Merge pull request #202 from Rory-Johnston/feature/SUP-5232
(SUP-5232) Added error handling to JSON conversion of metrics
2 parents ea98c34 + 05cf01b commit ffd12b7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

files/pe_metrics.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ def post_endpoint(url, body)
7979
end
8080

8181
def retrieve_additional_metrics(url, _metrics_type, metrics)
82-
metrics_output = post_endpoint(url, metrics.to_json)
82+
begin
83+
json_data = metrics.to_json
84+
rescue StandardError => e
85+
STDERR.puts 'Failed to convert metrics to JSON.'
86+
STDERR.puts "Error: #{e.message}"
87+
STDERR.puts e.backtrace
88+
return []
89+
end
90+
91+
metrics_output = post_endpoint(url, json_data)
8392
return [] if metrics_output.empty?
8493

8594
# For a status other than 200 or 404, add the HTTP code to the error array

0 commit comments

Comments
 (0)