From 7a1dab3319c9b5405ec88a73ab91c70c4ecaa812 Mon Sep 17 00:00:00 2001 From: r0fls Date: Fri, 5 Jan 2018 14:12:22 -0800 Subject: [PATCH] fix exception handling --- sanic/app.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index 26ef83b0..cf8f63d8 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -577,13 +577,17 @@ class Sanic: if isawaitable(response): response = await response except Exception as e: - if self.debug: + if isinstance(e, SanicException): + response = self.error_handler.default(request=request, + exception=e) + elif self.debug: response = HTTPResponse( "Error while handling error: {}\nStack: {}".format( - e, format_exc())) + e, format_exc()), status=500) else: response = HTTPResponse( - "An error occurred while handling an error") + "An error occurred while handling an error", + status=500) finally: # -------------------------------------------- # # Response Middleware