From 1b4f627833715a0e4cd78433416e21d96f1483d3 Mon Sep 17 00:00:00 2001 From: Carl Oscar Aaro Date: Fri, 2 Mar 2018 14:03:50 +0100 Subject: [PATCH] Handle WS exception --- tomodachi/transport/http.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tomodachi/transport/http.py b/tomodachi/transport/http.py index 3717ec250..36c02673c 100644 --- a/tomodachi/transport/http.py +++ b/tomodachi/transport/http.py @@ -432,9 +432,12 @@ async def _func(obj: Any, request: web.Request) -> None: if not context.get('log_level') or context.get('log_level') in ['DEBUG']: traceback.print_exception(e.__class__, e, e.__traceback__) elif message.type == WSMsgType.ERROR: - e = ws.exception() if not context.get('log_level') or context.get('log_level') in ['DEBUG']: - traceback.print_exception(e.__class__, e, e.__traceback__) + ws_exception = websocket.exception() + if isinstance(ws_exception, Exception): + traceback.print_exception(ws_exception.__class__, ws_exception, ws_exception.__traceback__) + else: + logging.getLogger('transport.http').warning('Websocket exception: "{}"'.format(ws_exception)) elif message.type == WSMsgType.CLOSED: break # noqa finally: