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):
|
||||
import logging
|
||||
_val_logger = logging.getLogger("nexus.validation")
|
||||
try:
|
||||
body = await request.body()
|
||||
_val_logger.warning(
|
||||
"422 validation error on %s %s body=%s errors=%s",
|
||||
request.method, request.url.path, body[:500], exc.errors(),
|
||||
)
|
||||
except Exception:
|
||||
_val_logger.warning("422 validation error on %s %s errors=%s", request.method, request.url.path, exc.errors())
|
||||
client_host = request.client.host if request.client else "unknown"
|
||||
content_type = request.headers.get("content-type", "")
|
||||
errors = exc.errors()
|
||||
_val_logger.warning(
|
||||
"422 %s %s from %s content_type=%s errors=%s",
|
||||
request.method, request.url.path, client_host, content_type, errors,
|
||||
)
|
||||
from fastapi.responses import JSONResponse
|
||||
return JSONResponse(status_code=422, content={"detail": exc.errors()})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user