From cb35d4bb66d31bb854b4ef52f03bd96582c84dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Thu, 21 Dec 2017 00:40:19 +0100 Subject: [PATCH] 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. --- mycroft/metrics/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mycroft/metrics/__init__.py b/mycroft/metrics/__init__.py index c3845bc28c..a2cb40554b 100644 --- a/mycroft/metrics/__init__.py +++ b/mycroft/metrics/__init__.py @@ -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):