mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-19 04:40:52 +08:00
fix(handlers): match raw error text before JSON body for duplicate detection
This commit is contained in:
@@ -618,11 +618,16 @@ func (h *BaseAPIHandler) WriteErrorResponse(c *gin.Context, msg *interfaces.Erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := BuildErrorResponseBody(status, errText)
|
body := BuildErrorResponseBody(status, errText)
|
||||||
// Check if this error body was already recorded by the executor (to avoid duplicate logging)
|
// Check if this error was already recorded by the executor (to avoid duplicate logging)
|
||||||
// This can happen when the last retry fails and both executor and handler try to log the same error
|
// The executor logs raw error text, so match errText before falling back to the JSON body.
|
||||||
shouldAppend := true
|
shouldAppend := true
|
||||||
if existing, exists := c.Get("API_RESPONSE"); exists {
|
if existing, exists := c.Get("API_RESPONSE"); exists {
|
||||||
if existingBytes, ok := existing.([]byte); ok && len(existingBytes) > 0 {
|
if existingBytes, ok := existing.([]byte); ok && len(existingBytes) > 0 {
|
||||||
|
trimmedErrText := strings.TrimSpace(errText)
|
||||||
|
if trimmedErrText != "" && bytes.Contains(existingBytes, []byte(trimmedErrText)) {
|
||||||
|
// Error already logged by executor, skip appending
|
||||||
|
shouldAppend = false
|
||||||
|
} else {
|
||||||
trimmedBody := bytes.TrimSpace(body)
|
trimmedBody := bytes.TrimSpace(body)
|
||||||
if len(trimmedBody) > 0 && bytes.Contains(existingBytes, trimmedBody) {
|
if len(trimmedBody) > 0 && bytes.Contains(existingBytes, trimmedBody) {
|
||||||
// Error already logged by executor, skip appending
|
// Error already logged by executor, skip appending
|
||||||
@@ -630,6 +635,7 @@ func (h *BaseAPIHandler) WriteErrorResponse(c *gin.Context, msg *interfaces.Erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if shouldAppend {
|
if shouldAppend {
|
||||||
// Use appendAPIResponse to preserve any previously captured API response data
|
// Use appendAPIResponse to preserve any previously captured API response data
|
||||||
// (such as formatted upstream response logs from logging_helpers.go)
|
// (such as formatted upstream response logs from logging_helpers.go)
|
||||||
|
|||||||
Reference in New Issue
Block a user