Repository navigation
fix(api): use public messages for account and service failures - #180
Open
jonathanfan-ee wants to merge 1 commit into
Open
jonathanfan-ee wants to merge 1 commit into
jonathanfan-ee wants to merge 1 commit into
Conversation
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.
改动 / Changes
账户需要重新登录时,公开 API 返回账户暂不可用的提示,具体账户邮箱与登录失败原因记录在管理端请求日志中。例如,OpenAI 请求收到 HTTP 503:
{"error":{"message":"Service unavailable: No available account for this request","type":"server_error","param":null,"code":"account_unavailable"}}错误消息由
publicRequestErrorMessage统一生成:No available account for this request。Upstream account unavailable。Rate limit exceeded;权限拒绝冷却:Service unavailable。OpenAI Chat、Responses、Anthropic Messages、Gemini、Interactions、Live 以及文件和媒体的相关错误输出使用上述处理。各协议继续提供 HTTP 状态、错误码和重试时间;参数校验错误提供具体字段说明。
验证 / Verification
本地执行
go test -mod=readonly -trimpath ./cmd/... ./internal/...,全部通过。新增单元测试:
TestPublicAccountErrors:以包含测试邮箱和登录 URL 的账户失效错误验证 OpenAI、Anthropic、Gemini HTTP 响应,OpenAI/Anthropic SSE,以及 Responses、Gemini 流、Interactions、Live 的错误对象;断言通用消息与管理日志中的完整错误。TestPublicErrorRetryAndValidation:验证 HTTP 429、Retry-After、OpenAI 重试提示、GeminiRetryInfo,以及 HTTP 400 字段校验提示和 HTTP 502 通用错误。TestPublicUpstreamAuthenticationError:验证带账户信息的上游 401/403 返回对应状态与通用账户提示。部署验证:指定不存在的测试账户,OpenAI 普通请求、
stream: true请求和 GeminigenerateContent均返回 HTTP 400 与通用账户提示。经 New API 转发的正常 Gemini 流式请求返回 HTTP 200、文本内容和[DONE]。