fix(twitter): 按 HTTP 状态翻译 API 错误 + 修 SearchTimeline queryId 误取#1890
Merged
jackwener merged 2 commits intoJun 11, 2026
Conversation
集中提升 Twitter 读命令在 API 失败时的可诊断性与 queryId 解析正确性。改动主要落在 `clis/twitter/shared.js`(被各读命令共享)。 ## describeTwitterApiError():按 HTTP 状态翻译 API 失败 各读命令的 API 失败原来统一抛 "queryId may have expired",掩盖真实原因。新增 `describeTwitterApiError(operation, status)` 按状态码翻译: - 429 → 会话配额限流,建议冷却 15-30 分钟后重试 - 401 → cookie 失效,需重新登录 - 403 → 权限不足 / 资源私密 - 404 → 资源不存在(删除 / 封禁 / 私密) - 5xx → 服务端瞬时错误,可重试 - 其他 → queryId 过期 / schema 变更 / 瞬时错误 调用方据此能区分限流 / 鉴权 / schema 变更 / 瞬时错误,采取重试 / 冷却 / 重新登录 / 丢弃等不同处理。覆盖 timeline / search / thread / tweets / likes / list-tweets / bookmarks / following / lists / profile / article 等读命令。 ## parseOperationFromBundleText() + queryId 解析修复 `resolveTwitterOperationMetadata()` 改用「operationName 锚定」正则解析 SearchTimeline 的 queryId,并采用 network / GitHub-first 回退顺序。修复此前在多 operation 的 bundle 文本里取到**错误 queryId** 的问题——旧逻辑按 bundle 优先,会静默返回相邻 operation 的 id,导致请求被 Twitter 拒绝、误报为 "queryId expired"。 ## 测试 - `parseOperationFromBundleText` 8 个用例:queryId 正序 / 反序、跨模块污染防护、operationName 缺失、跨对象距离过远、featureSwitches 回退、regex 元字符转义、空输入 - `describeTwitterApiError` 各状态码翻译 - twitter 全量:35 文件 / 411 用例通过;`tsc --noEmit` 干净;`npm run build` 干净 ## 兼容性 纯错误信息 / queryId 解析改进,不改任何输出字段语义。
This was referenced Jun 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
集中提升 Twitter 读命令在 API 失败时的可诊断性与 queryId 解析正确性。改动主要落在
clis/twitter/shared.js(被各读命令共享)。一、describeTwitterApiError():按 HTTP 状态翻译 API 失败
各读命令的 API 失败原来统一抛
"queryId may have expired",掩盖真实原因。新增describeTwitterApiError(operation, status)按状态码翻译:调用方据此能区分限流 / 鉴权 / schema 变更 / 瞬时错误,采取重试 / 冷却 / 重新登录 / 丢弃等不同处理。覆盖 timeline / search / thread / tweets / likes / list-tweets / bookmarks / following / lists / profile / article 等读命令。
二、parseOperationFromBundleText() + queryId 解析修复
resolveTwitterOperationMetadata()改用「operationName 锚定」正则解析 SearchTimeline 的 queryId,并采用 network / GitHub-first 回退顺序。修复此前在多 operation 的 bundle 文本里取到错误 queryId 的问题——旧逻辑按 bundle 优先,会静默返回相邻 operation 的 id,导致请求被 Twitter 拒绝、又被误报为 "queryId expired"。测试
parseOperationFromBundleText8 个用例:queryId 正序 / 反序、跨模块污染防护、operationName 缺失、跨对象距离过远、featureSwitches 回退、regex 元字符转义、空输入describeTwitterApiError各状态码翻译tsc --noEmit干净;npm run build干净兼容性
纯错误信息 / queryId 解析改进,不改任何输出字段语义。