debug: 422 handler 简化 — 只记录 errors 和 content_type,不读 body
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+7
-8
@@ -572,14 +572,13 @@ from fastapi.exceptions import RequestValidationError
|
|||||||
async def validation_error_handler(request: Request, exc: RequestValidationError):
|
async def validation_error_handler(request: Request, exc: RequestValidationError):
|
||||||
import logging
|
import logging
|
||||||
_val_logger = logging.getLogger("nexus.validation")
|
_val_logger = logging.getLogger("nexus.validation")
|
||||||
try:
|
client_host = request.client.host if request.client else "unknown"
|
||||||
body = await request.body()
|
content_type = request.headers.get("content-type", "")
|
||||||
_val_logger.warning(
|
errors = exc.errors()
|
||||||
"422 validation error on %s %s body=%s errors=%s",
|
_val_logger.warning(
|
||||||
request.method, request.url.path, body[:500], exc.errors(),
|
"422 %s %s from %s content_type=%s errors=%s",
|
||||||
)
|
request.method, request.url.path, client_host, content_type, errors,
|
||||||
except Exception:
|
)
|
||||||
_val_logger.warning("422 validation error on %s %s errors=%s", request.method, request.url.path, exc.errors())
|
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
return JSONResponse(status_code=422, content={"detail": exc.errors()})
|
return JSONResponse(status_code=422, content={"detail": exc.errors()})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user