diff --git a/sdk/api/handlers/handlers.go b/sdk/api/handlers/handlers.go index 86ed9276..5a24c63a 100644 --- a/sdk/api/handlers/handlers.go +++ b/sdk/api/handlers/handlers.go @@ -618,7 +618,22 @@ func (h *BaseAPIHandler) WriteErrorResponse(c *gin.Context, msg *interfaces.Erro } body := BuildErrorResponseBody(status, errText) - c.Set("API_RESPONSE", bytes.Clone(body)) + // Append first to preserve upstream response logs, then drop duplicate payloads if already recorded. + var previous []byte + if existing, exists := c.Get("API_RESPONSE"); exists { + if existingBytes, ok := existing.([]byte); ok && len(existingBytes) > 0 { + previous = bytes.Clone(existingBytes) + } + } + appendAPIResponse(c, body) + trimmedErrText := strings.TrimSpace(errText) + trimmedBody := bytes.TrimSpace(body) + if len(previous) > 0 { + if (trimmedErrText != "" && bytes.Contains(previous, []byte(trimmedErrText))) || + (len(trimmedBody) > 0 && bytes.Contains(previous, trimmedBody)) { + c.Set("API_RESPONSE", previous) + } + } if !c.Writer.Written() { c.Writer.Header().Set("Content-Type", "application/json")