From 05db656fd10d47a2dd3fc708cbe8eb7d33793e7c Mon Sep 17 00:00:00 2001 From: vinland100 Date: Fri, 16 Jan 2026 10:21:30 +0800 Subject: [PATCH] feat: Add specific rate limit error messages for ZIP task analysis, instant analysis, and repository scanning. --- backend/app/api/v1/endpoints/scan.py | 7 +++++++ backend/app/main.py | 2 +- backend/app/services/scanner.py | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/app/api/v1/endpoints/scan.py b/backend/app/api/v1/endpoints/scan.py index c43e411..a220455 100644 --- a/backend/app/api/v1/endpoints/scan.py +++ b/backend/app/api/v1/endpoints/scan.py @@ -164,6 +164,11 @@ async def process_zip_task(task_id: str, file_path: str, db_session_factory, use except Exception as e: if attempt < MAX_RETRIES - 1: wait_time = (attempt + 1) * 2 + # 特殊处理限流错误提示 + error_str = str(e) + if "429" in error_str or "rate limit" in error_str.lower() or "额度不足" in error_str: + print(f"🚫 [限流提示] ZIP任务分析文件触发 LLM 频率限制 (429),建议在设置中降低并发数或增加请求间隔。文件: {f_path}") + print(f"⚠️ ZIP任务分析文件失败 ({f_path}), 正在进行第 {attempt+1} 次重试... 错误: {e}") await asyncio.sleep(wait_time) continue @@ -487,6 +492,8 @@ async def instant_analysis( except Exception as e: # 分析失败,返回错误信息 error_msg = str(e) + if "429" in error_msg or "rate limit" in error_msg.lower() or "额度不足" in error_msg: + print(f"🚫 [限流提示] 即时分析触发 LLM 频率限制 (429),请检查账户余额或稍后重试。") print(f"❌ 即时分析失败: {error_msg}") raise HTTPException( status_code=500, diff --git a/backend/app/main.py b/backend/app/main.py index a4a791a..978c6df 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -13,7 +13,7 @@ from app.core.timezone import beijing_time # 配置日志 logging.Formatter.converter = beijing_time logging.basicConfig( - level=logging.DEBUG, + level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S' ) diff --git a/backend/app/services/scanner.py b/backend/app/services/scanner.py index d206d93..bc4af91 100644 --- a/backend/app/services/scanner.py +++ b/backend/app/services/scanner.py @@ -625,6 +625,11 @@ async def scan_repo_task(task_id: str, db_session_factory, user_config: dict = N except Exception as e: if attempt < MAX_RETRIES - 1: wait_time = (attempt + 1) * 2 + # 特殊处理限流错误提示 + error_str = str(e) + if "429" in error_str or "rate limit" in error_str.lower() or "额度不足" in error_str: + print(f"🚫 [限流提示] 仓库扫描任务触发 LLM 频率限制 (429),建议在设置中降低并发数或增加请求间隔。文件: {f_path}") + print(f"⚠️ 分析文件失败 ({f_path}), 正在进行第 {attempt+1} 次重试... 错误: {e}") await asyncio.sleep(wait_time) continue