Skip to content

Commit 3b8d10d

Browse files
committed
Handle error for Zulip UpdateMessageApiRequest
1 parent 14d099c commit 3b8d10d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/zulip.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ pub struct UpdateMessageApiRequest<'a> {
651651
}
652652

653653
impl<'a> UpdateMessageApiRequest<'a> {
654-
pub async fn send(&self, client: &reqwest::Client) -> anyhow::Result<reqwest::Response> {
654+
pub async fn send(&self, client: &reqwest::Client) -> anyhow::Result<()> {
655655
let bot_api_token = env::var("ZULIP_API_TOKEN").expect("ZULIP_API_TOKEN");
656656

657657
#[derive(serde::Serialize)]
@@ -664,7 +664,7 @@ impl<'a> UpdateMessageApiRequest<'a> {
664664
pub content: Option<&'a str>,
665665
}
666666

667-
Ok(client
667+
let resp = client
668668
.patch(&format!(
669669
"{}/api/v1/messages/{}",
670670
*ZULIP_URL, self.message_id
@@ -676,7 +676,21 @@ impl<'a> UpdateMessageApiRequest<'a> {
676676
content: self.content,
677677
})
678678
.send()
679-
.await?)
679+
.await
680+
.context("failed to send Zulip API Update Message")?;
681+
682+
let status = resp.status();
683+
684+
if !status.is_success() {
685+
let body = resp
686+
.text()
687+
.await
688+
.context("fail receiving Zulip API response (when updating the message)")?;
689+
690+
anyhow::bail!(body)
691+
}
692+
693+
Ok(())
680694
}
681695
}
682696

0 commit comments

Comments
 (0)