fix: 当 /api/usage 返回无效数据时,fallback 到 /api/subscription#27
Merged
Conversation
修复 Issue #26:接口不返回用量数据 ## 问题 88code 的 /api/usage 接口返回的 creditLimit、currentCredits、 subscriptionEntityList 字段全是 null,导致状态栏无法正确显示用量。 ## 解决方案 采用双重保障策略:优先使用 /api/usage,失败时 fallback 到 /api/subscription 1. 添加自定义反序列化函数处理 null 值(转换为默认值) 2. 新增 is_valid() 方法判断 usage 数据是否有效 3. 新增 SubscriptionPlan 结构体解析嵌套的 creditLimit 4. 新增 from_subscriptions() 方法从订阅数据构造等价的 UsageData 5. 在 get_usage() 中加入 fallback 逻辑 6. 修复 fetch_usage_with_cache() 传入正确的 subscription_url ## 优势 - 向后兼容:88code 修复接口后自动恢复原方案 - 当前可用:接口没修复时 subscription 方案兜底 - 最小改动:原方案代码基本不动,只加判断层 Closes #26 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Closed
johnnyee
added a commit
that referenced
this pull request
Jan 5, 2026
- 在分支列表中添加 fix/issue-26-usage-api-fallback - 在已提交的 PR 中添加 PR #27 - 添加详细的 Issue #26 修复说明文档 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
/api/usage返回无效数据(creditLimit=null, subscriptionEntityList=null)时,自动 fallback 到/api/subscription获取用量数据问题原因
88code 的
/api/usage接口返回的关键字段全是 null,导致状态栏无法正确显示用量。解决方案
采用双重保障策略:优先使用原接口,失败时 fallback
is_valid()方法判断 usage 数据是否有效SubscriptionPlan结构体解析嵌套的creditLimitfrom_subscriptions()方法从订阅数据构造等价的 UsageDataget_usage()中加入 fallback 逻辑fetch_usage_with_cache()传入正确的subscription_url优势
Test plan
Closes #26
🤖 Generated with Claude Code