fix(channels): check response status in send() for Telegram, Slack, and Discord
Reliability fix: check HTTP response status in channel send methods
This commit is contained in:
parent
64a64ccd3a
commit
ef00cc9a66
4 changed files with 49 additions and 5 deletions
|
|
@ -87,13 +87,23 @@ impl Channel for DiscordChannel {
|
|||
let url = format!("https://discord.com/api/v10/channels/{channel_id}/messages");
|
||||
let body = json!({ "content": message });
|
||||
|
||||
self.client
|
||||
let resp = self
|
||||
.client
|
||||
.post(&url)
|
||||
.header("Authorization", format!("Bot {}", self.bot_token))
|
||||
.json(&body)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if !resp.status().is_success() {
|
||||
let status = resp.status();
|
||||
let err = resp
|
||||
.text()
|
||||
.await
|
||||
.unwrap_or_else(|e| format!("<failed to read response body: {e}>"));
|
||||
anyhow::bail!("Discord send message failed ({status}): {err}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue