Skip to content

Commit b9c31fa

Browse files
authored
Merge pull request Wei-Shaw#999 from InCerryGit/fix/enc_coot
fix: handle invalid encrypted content error and retry logic.
2 parents 17b3399 + 8f0ea7a commit b9c31fa

4 files changed

Lines changed: 966 additions & 103 deletions

File tree

backend/internal/service/gateway_service.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6129,6 +6129,29 @@ func extractUpstreamErrorMessage(body []byte) string {
61296129
return gjson.GetBytes(body, "message").String()
61306130
}
61316131

6132+
func extractUpstreamErrorCode(body []byte) string {
6133+
if code := strings.TrimSpace(gjson.GetBytes(body, "error.code").String()); code != "" {
6134+
return code
6135+
}
6136+
6137+
inner := strings.TrimSpace(gjson.GetBytes(body, "error.message").String())
6138+
if !strings.HasPrefix(inner, "{") {
6139+
return ""
6140+
}
6141+
6142+
if code := strings.TrimSpace(gjson.Get(inner, "error.code").String()); code != "" {
6143+
return code
6144+
}
6145+
6146+
if lastBrace := strings.LastIndex(inner, "}"); lastBrace >= 0 {
6147+
if code := strings.TrimSpace(gjson.Get(inner[:lastBrace+1], "error.code").String()); code != "" {
6148+
return code
6149+
}
6150+
}
6151+
6152+
return ""
6153+
}
6154+
61326155
func isCountTokensUnsupported404(statusCode int, body []byte) bool {
61336156
if statusCode != http.StatusNotFound {
61346157
return false

0 commit comments

Comments
 (0)