@@ -13,6 +13,9 @@ from model.models import AgentConfig,OperationType | |||
from common.utils import * | |||
from common.memory import * | |||
import traceback | |||
import sys | |||
timeout_duration = 8.0 | |||
messages_router = APIRouter() | |||
@@ -53,8 +56,17 @@ async def get_messages(request: Request, body: Dict[str, Any]): | |||
return {"message": "收到微信回调消息,处理完成"} | |||
except Exception as e: | |||
logger.error(f"无法解析微信回调消息: {body} {e}") | |||
return {"message": "无法解析微信回调消息"} | |||
# 获取当前的堆栈跟踪 | |||
tb = sys.exc_info()[2] | |||
# 为异常附加堆栈跟踪 | |||
e = e.with_traceback(tb) | |||
# 输出详细的错误信息 | |||
logger.error(f"处理微信回调消息出错: {body}") | |||
logger.error(f"异常类型: {type(e).__name__}") | |||
logger.error(f"异常信息: {str(e)}") | |||
logger.error(f"堆栈跟踪: {traceback.format_exc()}") | |||
return {"message": "处理微信回调消息错误"} | |||
@@ -6,6 +6,7 @@ from starlette.responses import JSONResponse | |||
from pydantic import BaseModel | |||
from datetime import datetime | |||
import logging | |||
import uuid | |||
from common.log import logger | |||
@@ -121,6 +122,9 @@ async def http_context_v1(request: Request, call_next): | |||
return JSONResponse(content=result.model_dump(), status_code=response.status_code) | |||
async def http_context(request: Request, call_next): | |||
# 生成唯一ID | |||
request_id = str(uuid.uuid4()) | |||
# 检查请求大小 | |||
content_length = request.headers.get("content-length") | |||
if content_length and int(content_length) > MAX_REQUEST_SIZE: | |||
@@ -150,7 +154,7 @@ async def http_context(request: Request, call_next): | |||
except Exception as e: | |||
request_info["body"] = f"Error reading body: {str(e)}" | |||
logger.info(f"请求: {json.dumps(request_info, separators=(',', ':'), default=str, ensure_ascii=False)}") | |||
logger.info(f"{request_id} 请求: {json.dumps(request_info, separators=(',', ':'), default=str, ensure_ascii=False)}") | |||
# 调用下一个中间件或路由 | |||
response = await call_next(request) | |||
@@ -194,6 +198,6 @@ async def http_context(request: Request, call_next): | |||
"headers": dict(response.headers), | |||
"body": result.model_dump(), | |||
} | |||
logger.info(f"响应: {json.dumps(response_info, separators=(',', ':'), default=str, ensure_ascii=False)}") | |||
logger.info(f"{request_id} 响应: {json.dumps(response_info, separators=(',', ':'), default=str, ensure_ascii=False)}") | |||
return JSONResponse(content=result.model_dump(), status_code=response.status_code) |
@@ -909,7 +909,10 @@ class GeWeService: | |||
hash_key = f"__AI_OPS_WX__:GROUPS_MEMBERS:{wxid}" | |||
# 获取群信息 | |||
ret, msg, data = await self.get_group_memberlist_async(token_id, app_id, chatroom_id) | |||
ret, msg, data = await self.get_group_memberlist_async(token_id, app_id, chatroom_id) | |||
if ret != 200: | |||
logger.error(f"获取{chatroom_id}群成员信息失败,错误信息:{ret} {msg}") | |||
return | |||
await self.redis_service.update_hash_field(hash_key, chatroom_id, json.dumps(data, ensure_ascii=False)) | |||
async def get_group_members_from_cache_async(self, wxid,chatroom_id)->dict: | |||
@@ -984,7 +987,11 @@ class GeWeService: | |||
hash_key = f"__AI_OPS_WX__:GROUPS_INFO:{wxid}" | |||
# 获取群信息 | |||
ret, msg, data =await self.get_chatroom_info_async(token_id, app_id, chatroom_id) | |||
ret, msg, data =await self.get_chatroom_info_async(token_id, app_id, chatroom_id) | |||
if ret != 200: | |||
logger.error(f"获取{chatroom_id}群成员信息失败,错误信息:{ret} {msg}") | |||
return | |||
await self.redis_service.update_hash_field(hash_key, chatroom_id, json.dumps(data, ensure_ascii=False)) | |||
async def get_groups_info_from_cache_async(self, wxid)->list: | |||