chore: Handle failed banning properly
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
f3561b5efd
commit
3664d06d17
2 changed files with 10 additions and 2 deletions
|
@ -14,6 +14,8 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://gnu.org/licenses/agpl.txt>.
|
// along with this program. If not, see <https://gnu.org/licenses/agpl.txt>.
|
||||||
|
|
||||||
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
use crate::config::{CONFIG_PATH_ENV, DEFAULT_CONFIG_PATH};
|
use crate::config::{CONFIG_PATH_ENV, DEFAULT_CONFIG_PATH};
|
||||||
|
|
||||||
/// Result of the guard
|
/// Result of the guard
|
||||||
|
@ -39,4 +41,7 @@ pub enum GuardError {
|
||||||
/// Faild to deserialize the config file
|
/// Faild to deserialize the config file
|
||||||
#[error("Failed to deserialize the config: {0}")]
|
#[error("Failed to deserialize the config: {0}")]
|
||||||
FaildDeserializeConfig(#[from] toml::de::Error),
|
FaildDeserializeConfig(#[from] toml::de::Error),
|
||||||
|
/// Failed to ban the user
|
||||||
|
#[error("Failed to ban the user, status code: {0}")]
|
||||||
|
FailedToBan(StatusCode),
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
|
|
||||||
use crate::error::GuardResult;
|
use crate::error::{GuardError, GuardResult};
|
||||||
|
|
||||||
/// Ban a user from the instance, purging their data.
|
/// Ban a user from the instance, purging their data.
|
||||||
pub async fn ban_user(
|
pub async fn ban_user(
|
||||||
|
@ -34,7 +34,10 @@ pub async fn ban_user(
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
tracing::debug!("Ban user response: {:?}", &res);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue