From 25d65b0a947fc1688b29ef461f9eac0c1b61f402 Mon Sep 17 00:00:00 2001 From: tbphp Date: Sat, 12 Jul 2025 11:22:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A5=E5=BF=97=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/proxy/server.go | 17 +++++++++++------ internal/types/types.go | 9 +++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/proxy/server.go b/internal/proxy/server.go index c0c3f51..b72478a 100644 --- a/internal/proxy/server.go +++ b/internal/proxy/server.go @@ -109,10 +109,14 @@ func (ps *ProxyServer) executeRequestWithRetry( } else { response.Error(c, app_errors.NewAPIErrorWithUpstream(lastError.StatusCode, "UPSTREAM_ERROR", lastError.ErrorMessage)) } - logrus.Debugf("Max retries exceeded for group %s after %d attempts. Parsed Error: %s", group.Name, retryCount, lastError.ErrorMessage) + logMessage := lastError.ParsedErrorMessage + if logMessage == "" { + logMessage = lastError.ErrorMessage + } + logrus.Debugf("Max retries exceeded for group %s after %d attempts. Parsed Error: %s", group.Name, retryCount, logMessage) keyID, _ := strconv.ParseUint(lastError.KeyID, 10, 64) - ps.logRequest(c, group, uint(keyID), startTime, lastError.StatusCode, retryCount, errors.New(lastError.ErrorMessage)) + ps.logRequest(c, group, uint(keyID), startTime, lastError.StatusCode, retryCount, errors.New(logMessage)) } else { response.Error(c, app_errors.ErrMaxRetriesExceeded) logrus.Debugf("Max retries exceeded for group %s after %d attempts.", group.Name, retryCount) @@ -203,10 +207,11 @@ func (ps *ProxyServer) executeRequestWithRetry( } newRetryErrors := append(retryErrors, types.RetryError{ - StatusCode: statusCode, - ErrorMessage: errorMessage, - KeyID: fmt.Sprintf("%d", apiKey.ID), - Attempt: retryCount + 1, + StatusCode: statusCode, + ErrorMessage: errorMessage, + ParsedErrorMessage: parsedError, + KeyID: fmt.Sprintf("%d", apiKey.ID), + Attempt: retryCount + 1, }) ps.executeRequestWithRetry(c, channelHandler, group, bodyBytes, isStream, startTime, retryCount+1, newRetryErrors) return diff --git a/internal/types/types.go b/internal/types/types.go index fe6e5a7..fcd90d2 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -79,8 +79,9 @@ type DatabaseConfig struct { } type RetryError struct { - StatusCode int `json:"status_code"` - ErrorMessage string `json:"error_message"` - KeyID string `json:"key_id"` - Attempt int `json:"attempt"` + StatusCode int `json:"status_code"` + ErrorMessage string `json:"error_message"` + ParsedErrorMessage string `json:"-"` + KeyID string `json:"key_id"` + Attempt int `json:"attempt"` }