diff --git a/src/app/twitch.rs b/src/app/twitch.rs index 626445e..8e034fc 100644 --- a/src/app/twitch.rs +++ b/src/app/twitch.rs @@ -191,13 +191,25 @@ pub async fn handle_pubsub(state: Arc, event: WsMessage) -> anyhow::Resul async fn rename_a_split(state: Arc, redemption: &Redemption) { let input = match &redemption.user_input { Some(i) => i, - None => return, + None => { + if let Err(e) = update_redemption_status(&*state, &redemption, CustomRewardRedemptionStatus::Canceled).await { + eprintln!("could not update redemption status: {:?}", e); + } + + return; + } }; let (old, new) = match input.split_once("=>") .or_else(|| input.split_once("->")) { Some(x) => x, - None => return, + None => { + if let Err(e) = update_redemption_status(&*state, &redemption, CustomRewardRedemptionStatus::Canceled).await { + eprintln!("could not update redemption status: {:?}", e); + } + + return; + } }; let fulfilled = match reqwest::Client::new() @@ -220,6 +232,12 @@ async fn rename_a_split(state: Arc, redemption: &Redemption) { CustomRewardRedemptionStatus::Canceled }; + if let Err(e) = update_redemption_status(&*state, &redemption, status).await { + eprintln!("could not update redemption status: {:?}", e); + } +} + +async fn update_redemption_status(state: &State, redemption: &Redemption, status: CustomRewardRedemptionStatus) -> anyhow::Result<()> { let req = UpdateRedemptionStatusRequest::builder() .broadcaster_id(state.user_config.twitch.channel_id.to_string()) .reward_id(redemption.reward.id.clone()) @@ -230,11 +248,11 @@ async fn rename_a_split(state: Arc, redemption: &Redemption) { .status(status) .build(); - if let Ok(token) = state.twitch.user_token().await { - if let Err(e) = state.twitch.client.helix.req_patch(req, body, &token).await { - eprintln!("could not update redemption status: {:?}", e); - } - } + let token = state.twitch.user_token().await?; + state.twitch.client.helix.req_patch(req, body, &token).await + .context("could not update redemption status")?; + + Ok(()) } async fn handle_channel_points_reply(state: Arc, reply: Box) -> anyhow::Result<()> {