From 15473e513714b60de5da8b85fea12e51c29fb9ba Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 9 Jan 2025 09:51:52 +0000 Subject: [PATCH] Correct HTTP status for NotFound error (fixes #5309) (#5313) --- crates/apub/src/http/mod.rs | 2 +- crates/utils/src/error.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index fc2fbf0d3..52e036376 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -110,7 +110,7 @@ pub(crate) async fn get_activity( .into(); let activity = SentActivity::read_from_apub_id(&mut context.pool(), &activity_id) .await - .with_lemmy_type(FederationError::CouldntFindActivity.into())?; + .with_lemmy_type(LemmyErrorType::NotFound)?; let sensitive = activity.sensitive; if sensitive { diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index 4f28aaa32..f1ce64d49 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -164,8 +164,6 @@ pub enum LemmyErrorType { #[cfg_attr(feature = "full", ts(export))] #[non_exhaustive] pub enum FederationError { - // TODO: merge into a single NotFound error - CouldntFindActivity, InvalidCommunity, CannotCreatePostOrCommentInDeletedOrRemovedCommunity, CannotReceivePage, @@ -246,6 +244,9 @@ cfg_if! { if self.error_type == LemmyErrorType::IncorrectLogin { return actix_web::http::StatusCode::UNAUTHORIZED; } + if self.error_type == LemmyErrorType::NotFound { + return actix_web::http::StatusCode::NOT_FOUND; + } match self.inner.downcast_ref::() { Some(diesel::result::Error::NotFound) => actix_web::http::StatusCode::NOT_FOUND, _ => actix_web::http::StatusCode::BAD_REQUEST,