[P1/高] BaseAdapter mapError 字符串匹配 401/429,会误匹配 URL 中的数字 #23

Open
opened 2026-07-21 21:55:51 +08:00 by thzxx · 0 comments
Owner

问题类型

缺陷 / 高 / LLM 适配器

文件位置

electron/harness/adapters/base-adapter.ts

问题描述

mapError 通过 err.message.includes('401') 判断认证失败,includes('429') 判断限流。
这会误匹配:

  • URL 中包含端口号 4291、4292 等
  • 错误消息中包含 "page 4 of 29"
  • 模型名如 gpt-4-29b

误判后:

  • 401 误判触发重新加载配置 toast
  • 429 误判触发指数退避重试,浪费资源

影响

  • 错误的错误处理逻辑
  • 不必要的重试或配置变更

建议修复

  1. 基于 HTTP status code:直接读取 fetch response.status
if (err.response?.status === 401) {
  return new MetonaError('AUTH_FAILED', 'Authentication failed', false);
}
if (err.response?.status === 429) {
  return new MetonaError('RATE_LIMITED', 'Rate limited', true);
}
  1. 正则严格匹配/\b401\b/ 使用单词边界
  2. 优先级:HTTP status > 错误码字段 > 消息字符串
## 问题类型 缺陷 / 高 / LLM 适配器 ## 文件位置 `electron/harness/adapters/base-adapter.ts` ## 问题描述 mapError 通过 `err.message.includes('401')` 判断认证失败,`includes('429')` 判断限流。 这会误匹配: - URL 中包含端口号 4291、4292 等 - 错误消息中包含 "page 4 of 29" - 模型名如 `gpt-4-29b` 误判后: - 401 误判触发重新加载配置 toast - 429 误判触发指数退避重试,浪费资源 ## 影响 - 错误的错误处理逻辑 - 不必要的重试或配置变更 ## 建议修复 1. **基于 HTTP status code**:直接读取 fetch response.status ```ts if (err.response?.status === 401) { return new MetonaError('AUTH_FAILED', 'Authentication failed', false); } if (err.response?.status === 429) { return new MetonaError('RATE_LIMITED', 'Rate limited', true); } ``` 2. **正则严格匹配**:`/\b401\b/` 使用单词边界 3. **优先级**:HTTP status > 错误码字段 > 消息字符串
thzxx added the LLM?????? labels 2026-07-21 21:55:51 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#23