Correct HTTP status for NotFound error (fixes #5309) (#5313)

This commit is contained in:
Nutomic 2025-01-09 09:51:52 +00:00 committed by GitHub
parent d83f96293d
commit 15473e5137
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View file

@ -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 {

View file

@ -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::<diesel::result::Error>() {
Some(diesel::result::Error::NotFound) => actix_web::http::StatusCode::NOT_FOUND,
_ => actix_web::http::StatusCode::BAD_REQUEST,