Skip to content

Commit 7ee0d7f

Browse files
committed
fix: remove unreachable retry fallbacks
1 parent c15318e commit 7ee0d7f

3 files changed

Lines changed: 0 additions & 63 deletions

File tree

proxy/handler.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,6 @@ func (h *Handler) Responses(c *gin.Context) {
789789
maxRateLimitRetries := h.getMaxRateLimitRetries()
790790
generalRetries := 0
791791
rateLimitRetries := 0
792-
var lastErr error
793792
var lastStatusCode int
794793
var lastBody []byte
795794
excludeAccounts := make(map[int64]bool) // 重试时排除已失败的账号
@@ -850,7 +849,6 @@ func (h *Handler) Responses(c *gin.Context) {
850849
}
851850

852851
log.Printf("上游请求失败 (attempt %d): %v", attempt+1, reqErr)
853-
lastErr = reqErr
854852
if shouldRetryRequestError(reqErr, &generalRetries, maxRetries) {
855853
continue
856854
}
@@ -1035,10 +1033,6 @@ func (h *Handler) Responses(c *gin.Context) {
10351033
resp.Body.Close()
10361034
h.store.Release(account)
10371035
h.store.UnbindSessionAffinity(affinityKey, account.ID())
1038-
lastErr = readErr
1039-
if lastErr == nil {
1040-
lastErr = errors.New(outcome.failureMessage)
1041-
}
10421036
continue
10431037
}
10441038

@@ -1109,15 +1103,6 @@ func (h *Handler) Responses(c *gin.Context) {
11091103
h.store.Release(account)
11101104
return
11111105
}
1112-
1113-
// 所有重试都失败
1114-
if lastErr != nil {
1115-
c.JSON(http.StatusBadGateway, gin.H{
1116-
"error": gin.H{"message": "上游请求失败: " + lastErr.Error(), "type": "upstream_error"},
1117-
})
1118-
} else if lastStatusCode != 0 {
1119-
h.sendFinalUpstreamError(c, lastStatusCode, lastBody)
1120-
}
11211106
}
11221107

11231108
// ResponsesCompact 处理 /v1/responses/compact 请求(非流式压缩接口,透传到上游 /responses/compact)
@@ -1192,7 +1177,6 @@ func (h *Handler) ResponsesCompact(c *gin.Context) {
11921177
maxRateLimitRetries := h.getMaxRateLimitRetries()
11931178
generalRetries := 0
11941179
rateLimitRetries := 0
1195-
var lastErr error
11961180
var lastStatusCode int
11971181
var lastBody []byte
11981182
excludeAccounts := make(map[int64]bool)
@@ -1243,7 +1227,6 @@ func (h *Handler) ResponsesCompact(c *gin.Context) {
12431227
}
12441228

12451229
log.Printf("compact 上游请求失败 (attempt %d): %v", attempt+1, reqErr)
1246-
lastErr = reqErr
12471230
if shouldRetryRequestError(reqErr, &generalRetries, maxRetries) {
12481231
continue
12491232
}
@@ -1332,15 +1315,6 @@ func (h *Handler) ResponsesCompact(c *gin.Context) {
13321315
c.Data(http.StatusOK, "application/json", respBody)
13331316
return
13341317
}
1335-
1336-
// 所有重试都失败
1337-
if lastErr != nil {
1338-
c.JSON(http.StatusBadGateway, gin.H{
1339-
"error": gin.H{"message": "上游请求失败: " + lastErr.Error(), "type": "upstream_error"},
1340-
})
1341-
} else if lastStatusCode != 0 {
1342-
h.sendFinalUpstreamError(c, lastStatusCode, lastBody)
1343-
}
13441318
}
13451319

13461320
func (h *Handler) ChatCompletions(c *gin.Context) {
@@ -1414,7 +1388,6 @@ func (h *Handler) ChatCompletions(c *gin.Context) {
14141388
maxRateLimitRetries := h.getMaxRateLimitRetries()
14151389
generalRetries := 0
14161390
rateLimitRetries := 0
1417-
var lastErr error
14181391
var lastStatusCode int
14191392
var lastBody []byte
14201393
excludeAccounts := make(map[int64]bool) // 重试时排除已失败的账号
@@ -1475,7 +1448,6 @@ func (h *Handler) ChatCompletions(c *gin.Context) {
14751448
}
14761449

14771450
log.Printf("上游请求失败 (attempt %d): %v", attempt+1, reqErr)
1478-
lastErr = reqErr
14791451
if shouldRetryRequestError(reqErr, &generalRetries, maxRetries) {
14801452
continue
14811453
}
@@ -1654,10 +1626,6 @@ func (h *Handler) ChatCompletions(c *gin.Context) {
16541626
resp.Body.Close()
16551627
h.store.Release(account)
16561628
h.store.UnbindSessionAffinity(affinityKey, account.ID())
1657-
lastErr = readErr
1658-
if lastErr == nil {
1659-
lastErr = errors.New(outcome.failureMessage)
1660-
}
16611629
continue
16621630
}
16631631

@@ -1727,15 +1695,6 @@ func (h *Handler) ChatCompletions(c *gin.Context) {
17271695
h.store.Release(account)
17281696
return
17291697
}
1730-
1731-
// 所有重试都失败
1732-
if lastErr != nil {
1733-
c.JSON(http.StatusBadGateway, gin.H{
1734-
"error": gin.H{"message": "上游请求失败: " + lastErr.Error(), "type": "upstream_error"},
1735-
})
1736-
} else if lastStatusCode != 0 {
1737-
h.sendFinalUpstreamError(c, lastStatusCode, lastBody)
1738-
}
17391698
}
17401699

17411700
// handleStreamResponse 处理流式响应(翻译 Codex → OpenAI)

proxy/handler_anthropic.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package proxy
22

33
import (
4-
"errors"
54
"fmt"
65
"io"
76
"log"
@@ -127,7 +126,6 @@ func (h *Handler) Messages(c *gin.Context) {
127126
maxRateLimitRetries := h.getMaxRateLimitRetries()
128127
generalRetries := 0
129128
rateLimitRetries := 0
130-
var lastErr error
131129
var lastStatusCode int
132130
var lastBody []byte
133131
excludeAccounts := make(map[int64]bool)
@@ -187,7 +185,6 @@ func (h *Handler) Messages(c *gin.Context) {
187185
}
188186

189187
log.Printf("上游请求失败 (attempt %d, /v1/messages): %v", attempt+1, reqErr)
190-
lastErr = reqErr
191188
if shouldRetryRequestError(reqErr, &generalRetries, maxRetries) {
192189
continue
193190
}
@@ -384,10 +381,6 @@ func (h *Handler) Messages(c *gin.Context) {
384381
resp.Body.Close()
385382
h.store.Release(account)
386383
h.store.UnbindSessionAffinity(affinityKey, account.ID())
387-
lastErr = readErr
388-
if lastErr == nil {
389-
lastErr = errors.New(outcome.failureMessage)
390-
}
391384
continue
392385
}
393386

@@ -449,12 +442,4 @@ func (h *Handler) Messages(c *gin.Context) {
449442
h.store.Release(account)
450443
return
451444
}
452-
453-
// 所有重试都失败
454-
if lastErr != nil {
455-
sendAnthropicError(c, http.StatusBadGateway, "api_error", "Upstream request failed: "+lastErr.Error())
456-
} else if lastStatusCode != 0 {
457-
errType := mapHTTPStatusToAnthropicError(lastStatusCode)
458-
sendAnthropicError(c, lastStatusCode, errType, fmt.Sprintf("Upstream returned status %d", lastStatusCode))
459-
}
460445
}

proxy/images.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ func (h *Handler) forwardImagesRequest(c *gin.Context, inboundEndpoint, requestM
870870
maxRateLimitRetries := h.getMaxRateLimitRetries()
871871
generalRetries := 0
872872
rateLimitRetries := 0
873-
var lastErr error
874873
var lastStatusCode int
875874
var lastBody []byte
876875
excludeAccounts := make(map[int64]bool)
@@ -909,7 +908,6 @@ func (h *Handler) forwardImagesRequest(c *gin.Context, inboundEndpoint, requestM
909908
ErrorToGinResponse(c, reqErr)
910909
return
911910
}
912-
lastErr = reqErr
913911
if shouldRetryRequestError(reqErr, &generalRetries, maxRetries) {
914912
continue
915913
}
@@ -1021,11 +1019,6 @@ func (h *Handler) forwardImagesRequest(c *gin.Context, inboundEndpoint, requestM
10211019
return
10221020
}
10231021

1024-
if lastErr != nil {
1025-
c.JSON(http.StatusBadGateway, gin.H{"error": gin.H{"message": "上游请求失败: " + lastErr.Error(), "type": "upstream_error"}})
1026-
} else if lastStatusCode != 0 {
1027-
h.sendFinalUpstreamError(c, lastStatusCode, lastBody)
1028-
}
10291022
}
10301023

10311024
func collectImagesResponse(body io.Reader, responseFormat, fallbackModel string) ([]byte, *UsageInfo, int, imageUsageLogInfo, error) {

0 commit comments

Comments
 (0)