Skip to content

Commit

Permalink
Merge pull request #202 from Rory-Johnston/feature/SUP-5232
Browse files Browse the repository at this point in the history
(SUP-5232) Added error handling to JSON conversion of metrics
  • Loading branch information
MartyEwings authored Jan 7, 2025
2 parents ea98c34 + 05cf01b commit ffd12b7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion files/pe_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffd12b7

Please sign in to comment.