Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(channels): truncate Telegram and Discord upstream error bodies to 200 bytes (#22075)

ciel62d61ed26230
diff --git a/internal/channels/discord.go b/internal/channels/discord.go
index 5c113b6930..2ff5b8628a 100644
--- a/internal/channels/discord.go
+++ b/internal/channels/discord.go
@@ -624,7 +624,7 @@ func (c *discordChannel) requestJSON(ctx context.Context, method, path string, b
if resp.StatusCode == http.StatusTooManyRequests {
return newDiscordRateLimitError(resp.Header, respBody)
}
- return fmt.Errorf("discord api status: %d, response: %s", resp.StatusCode, string(respBody))
+ return fmt.Errorf("discord api status: %d, response: %.200s", resp.StatusCode, respBody)
}
if out != nil && len(bytes.TrimSpace(respBody)) > 0 {
return json.Unmarshal(respBody, out)
@@ -649,7 +649,7 @@ func newDiscordRateLimitError(header http.Header, body []byte) *discordRateLimit
return &discordRateLimitError{
RetryAfter: retryAfter,
Global: payload.Global,
- Response: strings.TrimSpace(string(body)),
+ Response: fmt.Sprintf("%.200s", strings.TrimSpace(string(body))),
}
}
diff --git a/internal/channels/telegram.go b/internal/channels/telegram.go
index 905ca6016b..651ef40d29 100644
--- a/internal/channels/telegram.go
+++ b/internal/channels/telegram.go
@@ -380,7 +380,7 @@ func (c *telegramChannel) callAPI(ctx context.Context, method string, params map
return err
}
if resp.StatusCode >= http.StatusBadRequest {
- return fmt.Errorf("Telegram API %s returned status %d: %s", method, resp.StatusCode, string(body))
+ return fmt.Errorf("Telegram API %s returned status %d: %.200s", method, resp.StatusCode, body)
}
var response telegramAPIResponse
@@ -388,7 +388,7 @@ func (c *telegramChannel) callAPI(ctx context.Context, method string, params map
return fmt.Errorf("Telegram API %s returned invalid JSON: %w", method, err)
}
if !response.OK {
- return fmt.Errorf("Telegram API %s failed: %s", method, response.Description)
+ return fmt.Errorf("Telegram API %s failed: %.200s", method, response.Description)
}
if out != nil && len(response.Result) > 0 {
if err := json.Unmarshal(response.Result, out); err != nil {