Handle network problems inside report_metric
Basically at any place where handle_metric is called I was adding a try-except
block to catch possible network/http issues. Due to this fact I feel
it's best to add it here.
@@ -33,8 +33,12 @@ def report_metric(name, data):
name (str): Name of metric. Must use only letters and hyphens
data (dict): JSON dictionary to report. Must be valid JSON
"""
+ try:
if Configuration().get()['opt_in']:
DeviceApi().report_metric(name, data)
+ except (requests.HTTPError, requests.exceptions.ConnectionError) as e:
+ LOG.error('Metric couldn\'t be uploaded, due to a network error ({})'
+ .format(e))
class Stopwatch(object):
