From 7edd1fcaed438a0566d37386ce8604f2565b4e6e Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Wed, 5 Oct 2016 15:49:06 -0400 Subject: [refactor] do not print traceback for expected errors Add the ability to declare an exceptions as 'expected'. This will avoid logging the backtrace on the bitmaskd log. We will just forward the message in the json that we return to the caller. - Resolves: #8506 --- src/leap/bitmask/core/dispatcher.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/leap/bitmask/core/dispatcher.py') diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py index 6a5603e6..783094ad 100644 --- a/src/leap/bitmask/core/dispatcher.py +++ b/src/leap/bitmask/core/dispatcher.py @@ -465,6 +465,16 @@ def _format_result(result): def _format_error(failure): - # TODO --- should check if the failure has the 'expected' attribute set - logger.failure('[DISPATCHER] Uncatched error:') + """ + Logs the failure backtrace, and returns a json containing the error + message. + """ + + # If a exception declares the 'expected' attribute as True, + # we will not print a full traceback + expected = getattr(failure.value, 'expected', False) + if not expected: + logger.failure('[DISPATCHER] Unexpected error:') + + # if needed, we could add here the exception type as an extra field return json.dumps({'error': failure.value.message, 'result': None}) -- cgit v1.2.3