我想为验证错误创建一个自定义处理程序。所以,我创建了自己的异常处理程序:
@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
上。我可以很好地获得协程本身,但它永远不会被执行(或者至少我猜是这样)。为什么会发生这种情况?