FastAPI 在 RequestValidationError 异常处理程序中等待等待

时间:2021-03-07 20:06:16

标签: python fastapi

我想为验证错误创建一个自定义处理程序。所以,我创建了自己的异常处理程序:

@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc):
    if "/couriers/" in request.url.path and request.method == "POST":
      
        data = await request.json()
        # Some logic

        return JSONResponse(content={"some": "content"}, status_code=400)

但是,显然,由于某种原因,它只是挂在 await 上。我可以很好地获得协程本身,但它永远不会被执行(或者至少我猜是这样)。为什么会发生这种情况?

0 个答案:

没有答案
相关问题