From 62d61ed26230d5dbb85f33d9d91b1a9c48003541 Mon Sep 17 00:00:00 2001 From: ciel <149575453+flyingwhit@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:25:47 +0800 Subject: [PATCH] fix(channels): truncate Telegram and Discord upstream error bodies to 200 bytes (#22075) --- internal/channels/discord.go | 4 ++-- internal/channels/telegram.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 {