fix: 日志错误格式修复

This commit is contained in:
tbphp
2025-07-12 11:22:01 +08:00
parent b3b1769411
commit 25d65b0a94
2 changed files with 16 additions and 10 deletions

View File

@@ -109,10 +109,14 @@ func (ps *ProxyServer) executeRequestWithRetry(
} else { } else {
response.Error(c, app_errors.NewAPIErrorWithUpstream(lastError.StatusCode, "UPSTREAM_ERROR", lastError.ErrorMessage)) 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) 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 { } else {
response.Error(c, app_errors.ErrMaxRetriesExceeded) response.Error(c, app_errors.ErrMaxRetriesExceeded)
logrus.Debugf("Max retries exceeded for group %s after %d attempts.", group.Name, retryCount) logrus.Debugf("Max retries exceeded for group %s after %d attempts.", group.Name, retryCount)
@@ -205,6 +209,7 @@ func (ps *ProxyServer) executeRequestWithRetry(
newRetryErrors := append(retryErrors, types.RetryError{ newRetryErrors := append(retryErrors, types.RetryError{
StatusCode: statusCode, StatusCode: statusCode,
ErrorMessage: errorMessage, ErrorMessage: errorMessage,
ParsedErrorMessage: parsedError,
KeyID: fmt.Sprintf("%d", apiKey.ID), KeyID: fmt.Sprintf("%d", apiKey.ID),
Attempt: retryCount + 1, Attempt: retryCount + 1,
}) })

View File

@@ -81,6 +81,7 @@ type DatabaseConfig struct {
type RetryError struct { type RetryError struct {
StatusCode int `json:"status_code"` StatusCode int `json:"status_code"`
ErrorMessage string `json:"error_message"` ErrorMessage string `json:"error_message"`
ParsedErrorMessage string `json:"-"`
KeyID string `json:"key_id"` KeyID string `json:"key_id"`
Attempt int `json:"attempt"` Attempt int `json:"attempt"`
} }