INNER CODE UNIT · Python

log_validation_error

Earth-OL-Player/ai_learn_project · ai-service/app/main.py:40

async def log_validation_error(request: Request, exc: RequestValidationError) -> Response:
    """记录 FastAPI 422 参数校验失败详情,便于排查 Java 传参问题。"""
    # 只记录元信息,不打印鉴权头和请求体,避免答案内容或 Token 出现在日志中。
    logger.warning(
        "Python AI 服务请求参数校验失败:traceId=%s method=%s path=%s contentType=%s contentLength=%s errors=%s",
        request.headers.get("x-trace-id", ""),
        request.method,
        request.url.path,
        request.headers.get("content-type", ""),
        request.headers.get("content-length", ""),
        [{"loc": error["loc"], "type": error["type"]} for error in exc.errors()],
    )
    return await request_validation_exception_handler(request, exc)


@app.get("/health")
def health() -> dict[str, str]:
    """健康检查。"""

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…