From 1d4a776b8f9c84d1d433e9df0e2f0154f90850a5 Mon Sep 17 00:00:00 2001 From: Denis-Cosmin NUTIU Date: Mon, 30 Dec 2024 19:02:17 +0200 Subject: [PATCH] return error on post when non success status code is received --- bot/src/bluesky.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bot/src/bluesky.rs b/bot/src/bluesky.rs index 664a47f..912a40b 100644 --- a/bot/src/bluesky.rs +++ b/bot/src/bluesky.rs @@ -2,6 +2,8 @@ pub(crate) mod atproto; mod token; use crate::bluesky::atproto::ATProtoServerCreateSession; +use anyhow::anyhow; +use log::warn; use reqwest::Body; use token::Token; @@ -42,16 +44,22 @@ impl BlueSkyClient { if token_expired { self.renew_token().await?; } - self.client + let response_code = self + .client .post("https://bsky.social/xrpc/com.atproto.repo.createRecord") .header("Content-Type", "application/json") .header( "Authorization", - format!("Bearer, {}", self.auth_token.access_jwt), + format!("Bearer {}", self.auth_token.access_jwt), ) .body(body) .send() - .await?; + .await? + .status(); + + if response_code != 200 { + return Err(anyhow!("Failed to post on BlueSky, got {response_code}")); + } Ok(()) } @@ -62,7 +70,7 @@ impl BlueSkyClient { .header("Content-Type", "application/json") .header( "Authorization", - format!("Bearer, {}", self.auth_token.refresh_jwt), + format!("Bearer {}", self.auth_token.refresh_jwt), ) .send() .await?