})
.await?;
if !is_mod_or_admin {
- return Err(ApiError::err("not_a_mod_or_admin").into());
+ return Err(ApiError::err_plain("not_a_mod_or_admin").into());
}
Ok(())
}
pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
if !local_user_view.person.admin {
- return Err(ApiError::err("not_an_admin").into());
+ return Err(ApiError::err_plain("not_an_admin").into());
}
Ok(())
}
pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
blocking(pool, move |conn| Post::read(conn, post_id))
.await?
- .map_err(|_| ApiError::err("couldnt_find_post").into())
+ .map_err(|_| ApiError::err_plain("couldnt_find_post").into())
}
pub async fn mark_post_as_read(
PostRead::mark_as_read(conn, &post_read_form)
})
.await?
- .map_err(|_| ApiError::err("couldnt_mark_post_as_read").into())
+ .map_err(|_| ApiError::err_plain("couldnt_mark_post_as_read").into())
}
pub async fn get_local_user_view_from_jwt(
secret: &Secret,
) -> Result<LocalUserView, LemmyError> {
let claims = Claims::decode(jwt, &secret.jwt_secret)
- .map_err(|_| ApiError::err("not_logged_in"))?
+ .map_err(|e| ApiError::err("not_logged_in", e))?
.claims;
let local_user_id = LocalUserId(claims.sub);
let local_user_view =
blocking(pool, move |conn| LocalUserView::read(conn, local_user_id)).await??;
// Check for a site ban
if local_user_view.person.banned {
- return Err(ApiError::err("site_ban").into());
+ return Err(ApiError::err_plain("site_ban").into());
}
// Check for user deletion
if local_user_view.person.deleted {
- return Err(ApiError::err("deleted").into());
+ return Err(ApiError::err_plain("deleted").into());
}
check_validator_time(&local_user_view.local_user.validator_time, &claims)?;
) -> Result<(), LemmyError> {
let user_validation_time = validator_time.timestamp();
if user_validation_time > claims.iat {
- Err(ApiError::err("not_logged_in").into())
+ Err(ApiError::err_plain("not_logged_in").into())
} else {
Ok(())
}
secret: &Secret,
) -> Result<LocalUserSettingsView, LemmyError> {
let claims = Claims::decode(jwt, &secret.jwt_secret)
- .map_err(|_| ApiError::err("not_logged_in"))?
+ .map_err(|e| ApiError::err("not_logged_in", e))?
.claims;
let local_user_id = LocalUserId(claims.sub);
let local_user_view = blocking(pool, move |conn| {
.await??;
// Check for a site ban
if local_user_view.person.banned {
- return Err(ApiError::err("site_ban").into());
+ return Err(ApiError::err_plain("site_ban").into());
}
check_validator_time(&local_user_view.local_user.validator_time, &claims)?;
let is_banned =
move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
if blocking(pool, is_banned).await? {
- Err(ApiError::err("community_ban").into())
+ Err(ApiError::err_plain("community_ban").into())
} else {
Ok(())
}
) -> Result<(), LemmyError> {
let is_blocked = move |conn: &'_ _| PersonBlock::read(conn, potential_blocker_id, my_id).is_ok();
if blocking(pool, is_blocked).await? {
- Err(ApiError::err("person_block").into())
+ Err(ApiError::err_plain("person_block").into())
} else {
Ok(())
}
if score == -1 {
let site = blocking(pool, move |conn| Site::read_simple(conn)).await??;
if !site.enable_downvotes {
- return Err(ApiError::err("downvotes_disabled").into());
+ return Err(ApiError::err_plain("downvotes_disabled").into());
}
}
Ok(())
/// Checks the password length
pub fn password_length_check(pass: &str) -> Result<(), LemmyError> {
if !(10..=60).contains(&pass.len()) {
- Err(ApiError::err("invalid_password").into())
+ Err(ApiError::err_plain("invalid_password").into())
} else {
Ok(())
}
/// Checks the site description length
pub fn site_description_length_check(description: &str) -> Result<(), LemmyError> {
if description.len() > 150 {
- Err(ApiError::err("site_description_length_overflow").into())
+ Err(ApiError::err_plain("site_description_length_overflow").into())
} else {
Ok(())
}
/// Checks for a honeypot. If this field is filled, fail the rest of the function
pub fn honeypot_check(honeypot: &Option<String>) -> Result<(), LemmyError> {
if honeypot.is_some() {
- Err(ApiError::err("honeypot_fail").into())
+ Err(ApiError::err_plain("honeypot_fail").into())
} else {
Ok(())
}