debug: 添加 422 验证错误日志 — 记录请求体和验证错误详情
诊断 Agent 心跳 422 问题,临时捕获请求体内容。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -564,6 +564,25 @@ async def custom_http_exception_handler(request: Request, exc: StarletteHTTPExce
|
||||
from fastapi.responses import JSONResponse
|
||||
return JSONResponse(status_code=exc.status_code, content={"detail": exc.detail})
|
||||
|
||||
|
||||
# ── Debug: log 422 validation errors with request body ──
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
|
||||
@app.exception_handler(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())
|
||||
from fastapi.responses import JSONResponse
|
||||
return JSONResponse(status_code=422, content={"detail": exc.errors()})
|
||||
|
||||
# ── Static files: serve web/app/ at /app/ (HTML pages + JS/CSS assets) ──
|
||||
# In production, Nginx serves these directly; this is for dev/standalone mode.
|
||||
WEB_APP_DIR = ROOT_DIR / "web" / "app"
|
||||
|
||||
Reference in New Issue
Block a user