fix exception handling

This commit is contained in:
r0fls 2018-01-05 14:12:22 -08:00
parent d63ec84745
commit 7a1dab3319

View File

@ -577,13 +577,17 @@ class Sanic:
if isawaitable(response): if isawaitable(response):
response = await response response = await response
except Exception as e: 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( response = HTTPResponse(
"Error while handling error: {}\nStack: {}".format( "Error while handling error: {}\nStack: {}".format(
e, format_exc())) e, format_exc()), status=500)
else: else:
response = HTTPResponse( response = HTTPResponse(
"An error occurred while handling an error") "An error occurred while handling an error",
status=500)
finally: finally:
# -------------------------------------------- # # -------------------------------------------- #
# Response Middleware # Response Middleware