def handle_exceptions(e):
# Log exception in your logs
# get traceback and sys exception info and log as required
# app.logger.error(getattr(e, 'description', str(e)))
# Print traceback
# return your response using getattr(e, 'code', 500) etc.
# Exception is used to catch all exceptions
app.register_error_handler(Exception, handle_exceptions)
试试这个:
Flask
为您提供了一个函数,使您能够在整个app
中注册一个错误处理程序;您可以执行如下所示的操作:老实说,这才是正道。-以{{CD3}}中发现的结构为例,是一个坚实的基础。在
拥有一个统一的异常处理程序来标准化您的
Exception
处理、可视化和日志记录将使您的生活稍微好一点。:)相关问题 更多 >
编程相关推荐