-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: change HTTP status code from 400 to 502 when no provider available #1174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: change HTTP status code from 400 to 502 when no provider available #1174
Conversation
Fixes router-for-me#1082 When all Antigravity accounts are unavailable, the error response now returns HTTP 502 (Bad Gateway) instead of HTTP 400 (Bad Request). This ensures that NewAPI and other clients will retry the request on a different channel, improving overall reliability.
Summary of ChangesHello @lieyan666, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在通过调整错误响应状态码来提高系统可靠性。之前,当没有可用的 Antigravity 账号时,系统返回 400 状态码,这导致 NewAPI 不会触发重试机制。通过将状态码更改为 502,NewAPI 现在能够识别这是一个服务端错误并进行重试,从而确保在临时性提供商不可用时请求能够得到更稳健的处理。 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 将在没有可用 provider 时返回的 HTTP 状态码从 400 修改为 502,目的是为了让客户端能够进行重试,从而提高系统的整体可靠性。这个修改符合 PR 的目标。我有一个小建议,可以使错误信息与新的 5xx 状态码的含义更加一致,以提高清晰度。
|
|
||
| if len(providers) == 0 { | ||
| return nil, "", &interfaces.ErrorMessage{StatusCode: http.StatusBadRequest, Error: fmt.Errorf("unknown provider for model %s", modelName)} | ||
| return nil, "", &interfaces.ErrorMessage{StatusCode: http.StatusBadGateway, Error: fmt.Errorf("unknown provider for model %s", modelName)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
将状态码更改为 http.StatusBadGateway (502) 以触发客户端重试是合理的。然而,当前的错误信息 unknown provider for model %s 更像是在描述一个永久性的配置问题(对应 4xx 错误),而不是一个临时性的服务问题(对应 5xx 错误)。
为了使错误信息与 5xx 状态码的意图(即可重试的临时故障)更加一致,建议将错误信息修改为更能反映临时性的描述,例如:no provider is currently available for model %s。
| return nil, "", &interfaces.ErrorMessage{StatusCode: http.StatusBadGateway, Error: fmt.Errorf("unknown provider for model %s", modelName)} | |
| return nil, "", &interfaces.ErrorMessage{StatusCode: http.StatusBadGateway, Error: fmt.Errorf("no provider is currently available for model %s", modelName)} |
|
@luispater @hkfires 两位大佬好,麻烦有空帮忙Review一下,这个PR仅仅修改了一个HTTP状态码,如果没问题的话求合并,感谢! |
问题描述
修复 #1082
当所有 Antigravity 账号都不可用时,CPA 之前返回 HTTP 400,但这会被 NewAPI 识别为请求错误而不进行重试,影响整体可靠性。
修改内容
将
sdk/api/handlers/handlers.go中getRequestDetails函数的错误响应状态码从http.StatusBadRequest(400) 修改为http.StatusBadGateway(502)。效果
HTTP 502 属于服务端错误,会触发 NewAPI 的错误重试机制,从而提高整体可靠性。
Problem Description
Fixes #1082
When all Antigravity accounts are unavailable, CPA previously returned HTTP 400. However, this status code is interpreted by NewAPI as a client request error, which prevents retry attempts and impacts overall system reliability.
Changes Made
Modified the error response status code in the getRequestDetails function within
sdk/api/handlers/handlers.go
from http.StatusBadRequest (400) to http.StatusBadGateway (502).
Impact
HTTP 502 is categorized as a server-side error, which triggers NewAPI's error retry mechanism, thereby improving overall system reliability.