- 新增 pkg/gemini: 模型定义与回退列表 - 新增 pkg/googleapi: Google API 错误状态处理 - 新增 pkg/geminicli/models.go: CLI 模型结构 - 更新 constants.go: AI Studio 相关常量 - 更新 oauth.go: 支持 AI Studio OAuth 流程,凭据通过环境变量配置
26 lines
560 B
Go
26 lines
560 B
Go
package googleapi
|
|
|
|
import "net/http"
|
|
|
|
// HTTPStatusToGoogleStatus maps HTTP status codes to Google-style error status strings.
|
|
func HTTPStatusToGoogleStatus(status int) string {
|
|
switch status {
|
|
case http.StatusBadRequest:
|
|
return "INVALID_ARGUMENT"
|
|
case http.StatusUnauthorized:
|
|
return "UNAUTHENTICATED"
|
|
case http.StatusForbidden:
|
|
return "PERMISSION_DENIED"
|
|
case http.StatusNotFound:
|
|
return "NOT_FOUND"
|
|
case http.StatusTooManyRequests:
|
|
return "RESOURCE_EXHAUSTED"
|
|
default:
|
|
if status >= 500 {
|
|
return "INTERNAL"
|
|
}
|
|
return "UNKNOWN"
|
|
}
|
|
}
|
|
|