0
点赞
收藏
分享

微信扫一扫

fastapi 处理 tortoise-orm相关异常

玩物励志老乐 2022-01-04 阅读 71
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": "服务器错误"
        }
    )
举报

相关推荐

0 条评论