Handle Piwik error response

This commit is contained in:
Alejandro Avilés 2014-10-15 14:12:27 +02:00
parent ca33b238b6
commit 9dc709dc95
2 changed files with 5 additions and 2 deletions

View File

@ -40,7 +40,6 @@ class PiwikQueryReportEventMetricDownloads(PiwikQueryReportEventMetricBase):
def _get_per_day_results(self, results):
hits_calendar = {}
# Piwik returns hits as a list of hits per date
for date, hits in results.iteritems():
day_hits = {'total': 0, 'unique': 0}
if hits:

View File

@ -10,7 +10,11 @@ def get_json_from_remote_server(func, default={}, **kwargs):
"""
rawjson = func(**kwargs)
try:
return json.loads(rawjson)
data = json.loads(rawjson)
if isinstance(data, dict) and data.get('result') == 'error':
current_plugin.get_logger().error('The Piwik server responded with an error: {}'.format(data['message']))
return {}
return data
except Exception:
current_plugin.get_logger().exception('Unable to load JSON from source {}'.format(str(rawjson)))
return default