其他分享
首页 > 其他分享> > fastapi 处理 tortoise-orm相关异常

fastapi 处理 tortoise-orm相关异常

作者:互联网

1:将add_exception_handlers设置为false
register_tortoise(
                  add_exception_handlers=False)

2:捕捉异常

@app.exception_handler(BaseORMException)
async def business_exception_handler(request: Request, error: BaseORMException):
    return JSONResponse(
        status_code=status.HTTP_200_OK,
        content={
            "code": status.HTTP_500_INTERNAL_SERVER_ERROR,
            "message": "服务器错误"
        }
    )

标签:status,exception,code,HTTP,tortoise,handler,fastapi,add,orm
来源: https://blog.csdn.net/qq_32319999/article/details/122307626