Do exception logging at Request level and discard duplicate exception messages between retries

This commit is contained in:
Fabio Manganiello 2019-01-13 20:09:25 +01:00
parent 8ea0519954
commit db4e68e247
2 changed files with 14 additions and 17 deletions

View file

@ -215,12 +215,15 @@ class Request(Message):
format(plugin, self.action, str(response)))
except Exception as e:
# Retry mechanism
plugin.logger.exception(e)
logger.warning(('Uncaught exception while processing response ' +
'from action {}.{}: {}').format(
plugin, self.action, str(e)))
errors = errors or []
errors.append(str(e))
if str(e) not in errors:
errors.append(str(e))
response = Response(output=None, errors=errors)
if n_tries-1 > 0:
logger.info('Reloading plugin {} and retrying'.format(module_name))

View file

@ -14,23 +14,17 @@ def action(f):
output = None
errors = []
try:
output = f(*args, **kwargs)
if output and isinstance(output, Response):
errors = output.errors \
if isinstance(output.errors, list) else [output.errors]
output = output.output
elif isinstance(output, tuple) and len(output) == 2:
errors = output[1] \
if isinstance(output[1], list) else [output[1]]
output = f(*args, **kwargs)
if output and isinstance(output, Response):
errors = output.errors \
if isinstance(output.errors, list) else [output.errors]
output = output.output
elif isinstance(output, tuple) and len(output) == 2:
errors = output[1] \
if isinstance(output[1], list) else [output[1]]
if len(errors) == 1 and errors[0] is None: errors = []
output = output[0]
except Exception as e:
if isinstance(args[0], Plugin):
args[0].logger.exception(e)
raise e
# errors.append(str(e) + '\n' + traceback.format_exc())
if len(errors) == 1 and errors[0] is None: errors = []
output = output[0]
return Response(output=output, errors=errors)