Skip to content

Commit 14d099c

Browse files
committed
Handle error for Zulip AddReaction
1 parent ea45e20 commit 14d099c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/zulip.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,18 +849,31 @@ struct AddReaction<'a> {
849849
}
850850

851851
impl<'a> AddReaction<'a> {
852-
pub async fn send(self, client: &reqwest::Client) -> anyhow::Result<reqwest::Response> {
852+
pub async fn send(self, client: &reqwest::Client) -> anyhow::Result<()> {
853853
let bot_api_token = env::var("ZULIP_API_TOKEN").expect("ZULIP_API_TOKEN");
854854

855-
Ok(client
855+
let resp = client
856856
.post(&format!(
857857
"{}/api/v1/messages/{}/reactions",
858858
*ZULIP_URL, self.message_id
859859
))
860860
.basic_auth(&*ZULIP_BOT_EMAIL, Some(&bot_api_token))
861861
.form(&self)
862862
.send()
863-
.await?)
863+
.await?;
864+
865+
let status = resp.status();
866+
867+
if !status.is_success() {
868+
let body = resp
869+
.text()
870+
.await
871+
.context("fail receiving Zulip API response (when adding a reaction)")?;
872+
873+
anyhow::bail!(body)
874+
}
875+
876+
Ok(())
864877
}
865878
}
866879

0 commit comments

Comments
 (0)