From 3664d06d170f264ea1aba908567800a19f7c0a31 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sat, 16 Nov 2024 11:57:55 +0000
Subject: [PATCH] chore: Handle failed banning properly
Signed-off-by: Awiteb
---
src/error.rs | 5 +++++
src/forgejo_api/ban_user.rs | 7 +++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/error.rs b/src/error.rs
index 341266f..9253873 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
+use reqwest::StatusCode;
+
use crate::config::{CONFIG_PATH_ENV, DEFAULT_CONFIG_PATH};
/// Result of the guard
@@ -39,4 +41,7 @@ pub enum GuardError {
/// Faild to deserialize the config file
#[error("Failed to deserialize the config: {0}")]
FaildDeserializeConfig(#[from] toml::de::Error),
+ /// Failed to ban the user
+ #[error("Failed to ban the user, status code: {0}")]
+ FailedToBan(StatusCode),
}
diff --git a/src/forgejo_api/ban_user.rs b/src/forgejo_api/ban_user.rs
index e61f12a..a0a2641 100644
--- a/src/forgejo_api/ban_user.rs
+++ b/src/forgejo_api/ban_user.rs
@@ -16,7 +16,7 @@
use reqwest::Method;
-use crate::error::GuardResult;
+use crate::error::{GuardError, GuardResult};
/// Ban a user from the instance, purging their data.
pub async fn ban_user(
@@ -34,7 +34,10 @@ pub async fn ban_user(
))
.await?;
tracing::debug!("Ban user response: {:?}", &res);
- tracing::debug!("Body: {}", res.text().await.unwrap_or_default());
+
+ if !res.status().is_success() {
+ return Err(GuardError::FailedToBan(res.status()));
+ }
Ok(())
}