mirror of
https://github.com/justlovemaki/AIClient-2-API.git
synced 2026-04-25 09:25:59 +03:00
[PR #241] [MERGED] feat(kiro): 改进错误处理逻辑,添加配额耗尽自动恢复机制 #316
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/AIClient-2-API-justlovemaki#316
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/justlovemaki/AIClient-2-API/pull/241
Author: @leonaii
Created: 1/14/2026
Status: ✅ Merged
Merged: 1/14/2026
Merged by: @justlovemaki
Base:
main← Head:main📝 Commits (3)
47e4e49feat(kiro): 添加凭证错误处理和配额恢复机制536f5f2Merge branch 'main' of https://github.com/leonaii/AIClient-2-API694cafcMerge branch 'justlovemaki:main' into main📊 Changes
3 files changed (+258 additions, -31 deletions)
View changed files
📝
src/providers/claude/claude-kiro.js(+137 -25)📝
src/providers/provider-pool-manager.js(+89 -0)📝
src/utils/common.js(+32 -6)📄 Description
🎯 问题描述
背景
Kiro Provider 在处理 API 错误时存在以下问题:
scheduledRecoveryTime字段未生效:虽然设置了该字段,但没有检查和自动恢复的逻辑,导致配额耗尽的凭证无法在下月自动恢复callApi()和streamApiReal()中有约 25 行重复的 402 错误处理代码影响
✅ 解决方案
1. 添加
scheduledRecoveryTime自动恢复机制 (高优先级)在
provider-pool-manager.js中新增_checkAndRecoverScheduledProviders()方法:scheduledRecoveryTime字段selectProvider()和performHealthChecks()中调用2. 改进凭证切换逻辑 (高优先级)
shouldSwitchCredential标记触发凭证切换skipErrorCount标记避免对临时错误(429/5xx)增加错误计数CREDENTIAL_SWITCH_MAX_RETRIES(默认 5)控制3. 提取重复的 402 处理逻辑 (中优先级)
新增
_handle402Error()私有方法,统一处理 402 错误:4. 提取下月 1 日计算方法 (低优先级)
新增
_getNextMonthFirstDay()方法,消除魔法数字:5. 创建自定义错误类 (低优先级)
新增
CredentialError类,为后续重构提供基础:📁 改动文件
src/providers/claude/claude-kiro.jsCredentialError类、_getNextMonthFirstDay()、_handle402Error()方法;改进 429/5xx 错误处理src/providers/provider-pool-manager.js_checkAndRecoverScheduledProviders()、markProviderUnhealthyWithRecoveryTime()方法src/utils/common.jsskipErrorCount和shouldSwitchCredential标记统计:3 个文件,+258 行,-31 行
🧪 测试说明
手动测试场景
402 配额耗尽测试
scheduledRecoveryTime是否设置为下月 1 日429 限流测试
errorCount是否未增加5xx 服务器错误测试
CREDENTIAL_SWITCH_MAX_RETRIES限制凭证池耗尽测试
⚠️ 破坏性变更
无破坏性变更
CREDENTIAL_SWITCH_MAX_RETRIES继续生效🔍 代码审查要点
_checkAndRecoverScheduledProviders()的调用时机是否合适?skipErrorCount和shouldSwitchCredential的命名是否清晰?CredentialError类添加更多使用场景?📊 性能影响
_checkAndRecoverScheduledProviders(): O(n),n 为提供商数量(通常 < 10),每次调用 < 0.1ms_debouncedSave()避免频繁文件 I/O结论:无明显性能影响
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.