代码500的自定义错误页面未在烧瓶中显示sqlalchemy错误

时间:2019-07-11 12:42:19

标签: python flask error-handling sqlalchemy

我想要一个针对内部错误的自定义错误页面。正确知道,我正在通过重新启动数据库服务并尝试在再次连接之前加载页面来对其进行测试。查询返回OperationalError

我已禁用调试模式,以使我不获取堆栈跟踪,但不是自定义500页,而是在白色背景上获取默认文本。

我不确定这是否是将sqlalchemy错误链接到自定义500页的正确方法。如果我没有为sqlalchemy定义事件监听器,则不会调用flask错误处理程序。

@db.event.listens_for(db.engine, "handle_error")
def handle_exception(context):
    internal_error(context.original_exception)

@app.errorhandler(500)
def internal_error(error):
    db.session.rollback()
    return render_template('500.html'), 500

删除sqlalchemy事件或在该位置重新引发错误也不起作用。

127.0.0.1 - - [11/Jul/2019 17:29:04] "GET /products HTTP/1.1" 500 -
Error on request:
...stack strace...
sqlalchemy.exc.OperationalError: (psycopg2.errors.AdminShutdown) terminating connection due to administrator command
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

更新:现在,我对此进行了思考。我认为这与sqlalchemy没有任何关系。我尝试用零除以查看是否将获得自定义页面,但还是发生了同样的事情。

0 个答案:

没有答案