Commit 4ce6eda7 authored by Bruno Duyé's avatar Bruno Duyé

Cleaner logs: add API errors "whitelist"

parent 44a81ac6
......@@ -65,6 +65,10 @@ API_URLs = {
'series_data': '{api_user_id}&method=GetData&DataSetName={dataset_code}&TableName={series_name}&Frequency={frequency_code}&Year=ALL',
# List of API errors descriptions that are not to be logged at info level, but debug
'No data exists for the Year/Frequencies passed.',
class APIException(Exception):
......@@ -126,12 +130,19 @@ def get_from_api(url, raise_on_errors=True):
"""Raise an error if raise_on_errors is True, else return True if tehre's an error"""
assert json
if 'Error' in json:
log.error('API error while getting {!r}'.format(url))
error_str = json['Error']
if raise_on_errors:
log.error('API error while getting {!r}'.format(url))
raise APIException(error_str)
if json['Error'].get('ErrorDetail') and json['Error']['ErrorDetail'].get('Description') and \
json['Error']['ErrorDetail']['Description'] in '|'.join(API_ERRORS_WHITELIST):
# This error is not to be logged as an error
log.debug('API error while getting {!r}'.format(url))
log.error('API error while getting {!r}'.format(url))
return True
return False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment