From: Nutomic Date: Wed, 8 Feb 2023 19:45:29 +0000 (+0900) Subject: Improved error message when attempting to fetch non-local object (fixes #2715) (... X-Git-Url: http://these/git/%7B%60%24%7BghostArchiveUrl%7D/static/%7Bpost_view.post.url%7D?a=commitdiff_plain;h=3bfa8ab4fffbacad50a2d20937bc64206cd4d3d0;p=lemmy.git Improved error message when attempting to fetch non-local object (fixes #2715) (#2717) --- diff --git a/crates/apub/src/http/comment.rs b/crates/apub/src/http/comment.rs index 5e7de7e2..6753271c 100644 --- a/crates/apub/src/http/comment.rs +++ b/crates/apub/src/http/comment.rs @@ -1,10 +1,9 @@ use crate::{ - http::{create_apub_response, create_apub_tombstone_response}, + http::{create_apub_response, create_apub_tombstone_response, err_object_not_local}, objects::comment::ApubComment, }; use activitypub_federation::traits::ApubObject; use actix_web::{web, web::Path, HttpResponse}; -use diesel::result::Error::NotFound; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud}; use lemmy_utils::error::LemmyError; @@ -24,7 +23,7 @@ pub(crate) async fn get_apub_comment( let id = CommentId(info.comment_id.parse::()?); let comment: ApubComment = Comment::read(context.pool(), id).await?.into(); if !comment.local { - return Err(NotFound.into()); + return Err(err_object_not_local()); } if !comment.deleted && !comment.removed { diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index 726834c0..83272d12 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -100,6 +100,10 @@ fn create_apub_tombstone_response>(id: T) -> HttpResponse { .json(WithContext::new(tombstone, CONTEXT.deref().clone())) } +fn err_object_not_local() -> LemmyError { + LemmyError::from_message("Object not local, fetch it from original instance") +} + #[derive(Deserialize)] pub struct ActivityQuery { type_: String, @@ -123,8 +127,10 @@ pub(crate) async fn get_activity( let activity = Activity::read_from_apub_id(context.pool(), &activity_id).await?; let sensitive = activity.sensitive.unwrap_or(true); - if !activity.local || sensitive { - Ok(HttpResponse::NotFound().finish()) + if !activity.local { + return Err(err_object_not_local()); + } else if sensitive { + Ok(HttpResponse::Forbidden().finish()) } else { Ok(create_json_apub_response(activity.data)) } diff --git a/crates/apub/src/http/post.rs b/crates/apub/src/http/post.rs index bea5da3a..fc164a54 100644 --- a/crates/apub/src/http/post.rs +++ b/crates/apub/src/http/post.rs @@ -1,10 +1,9 @@ use crate::{ - http::{create_apub_response, create_apub_tombstone_response}, + http::{create_apub_response, create_apub_tombstone_response, err_object_not_local}, objects::post::ApubPost, }; use activitypub_federation::traits::ApubObject; use actix_web::{web, HttpResponse}; -use diesel::result::Error::NotFound; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{newtypes::PostId, source::post::Post, traits::Crud}; use lemmy_utils::error::LemmyError; @@ -24,7 +23,7 @@ pub(crate) async fn get_apub_post( let id = PostId(info.post_id.parse::()?); let post: ApubPost = Post::read(context.pool(), id).await?.into(); if !post.local { - return Err(NotFound.into()); + return Err(err_object_not_local()); } if !post.deleted && !post.removed {