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.
pull/1354/head
Åke Forslund 2017-12-21 00:40:19 +01:00 committed by Steve Penrod
parent 72091f2b8e
commit cb35d4bb66
1 changed files with 6 additions and 2 deletions

View File

@ -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
"""
if Configuration().get()['opt_in']:
DeviceApi().report_metric(name, data)
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):