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": "服务器错误"
        }
    )

上一篇:多线程14:三大不安全案例


下一篇:单链表