Macroize various remaining Error constructions.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-04-26 23:50:03 +00:00 committed by Jade Ellis
commit 667afedd24
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2
9 changed files with 78 additions and 125 deletions

View file

@ -2,7 +2,7 @@ use std::{fmt::Write as _, ops::Mul, time::Duration};
use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use conduwuit::{Err, Error, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt};
use conduwuit::{Err, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt};
use conduwuit_service::Services;
use rand::Rng;
use ruma::{
@ -44,9 +44,8 @@ pub(crate) async fn report_room_route(
}
if body.reason.as_ref().is_some_and(|s| s.len() > 750) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Reason too long, should be 750 characters or fewer",
return Err!(Request(
InvalidParam("Reason too long, should be 750 characters or fewer",)
));
}
@ -149,9 +148,8 @@ pub(crate) async fn report_user_route(
}
if body.reason.as_ref().is_some_and(|s| s.len() > 750) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Reason too long, should be 750 characters or fewer",
return Err!(Request(
InvalidParam("Reason too long, should be 750 characters or fewer",)
));
}
@ -204,23 +202,16 @@ async fn is_event_report_valid(
);
if room_id != pdu.room_id {
return Err(Error::BadRequest(
ErrorKind::NotFound,
"Event ID does not belong to the reported room",
));
return Err!(Request(NotFound("Event ID does not belong to the reported room",)));
}
if score.is_some_and(|s| s > int!(0) || s < int!(-100)) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Invalid score, must be within 0 to -100",
));
return Err!(Request(InvalidParam("Invalid score, must be within 0 to -100",)));
}
if reason.as_ref().is_some_and(|s| s.len() > 750) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Reason too long, should be 750 characters or fewer",
return Err!(Request(
InvalidParam("Reason too long, should be 750 characters or fewer",)
));
}
@ -231,10 +222,7 @@ async fn is_event_report_valid(
.ready_any(|user_id| user_id == sender_user)
.await
{
return Err(Error::BadRequest(
ErrorKind::NotFound,
"You are not in the room you are reporting.",
));
return Err!(Request(NotFound("You are not in the room you are reporting.",)));
}
Ok(())