本文整理汇总了Python中sanic.Sanic.error_handler方法的典型用法代码示例。如果您正苦于以下问题:Python Sanic.error_handler方法的具体用法?Python Sanic.error_handler怎么用?Python Sanic.error_handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sanic.Sanic
的用法示例。
在下文中一共展示了Sanic.error_handler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: super
# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import error_handler [as 别名]
# Then, we must finish handling the exception by returning
# our response to the client
# For this we can just call the super class' default handler
return super().default(request, exception)
"""
This is an ordinary Sanic server, with the exception that we set the
server's error_handler to an instance of our CustomHandler
"""
from sanic import Sanic
from sanic.response import json
app = Sanic(__name__)
handler = CustomHandler(sanic=app)
app.error_handler = handler
@app.route("/")
async def test(request):
# Here, something occurs which causes an unexpected exception
# This exception will flow to our custom handler.
1 / 0
return json({"test": True})
app.run(host="0.0.0.0", port=8000, debug=True)