Merge pull request #1082 from channelcat/1042

fix exception handling
This commit is contained in:
Raphael Deem 2018-01-13 17:06:46 -08:00 committed by GitHub
commit ab97018c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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