Repository: LemmyNet/lemmy (language: rust)

Issue:
[Bug]: couldnt_find_post error causes HTTP status 500 and shows a generic error page 
### Requirements

- [X] Is this a bug report? For questions or discussions use https://lemmy.ml/c/lemmy_support
- [X] Did you check to see if this issue already exists?
- [X] Is this only a single bug? Do not put multiple bugs in one issue.
- [X] Do you agree to follow the rules in our [Code of Conduct](https://join-lemmy.org/docs/code_of_conduct.html)?
- [X] Is this a backend issue? Use the [lemmy-ui](https://github.com/LemmyNet/lemmy-ui) repo for UI / frontend issues.

### Summary

[What is Lemmy.ml](https://lemmy.ml/post/70280) responds with:
> Error!
> There was an error on the server. Try refreshing your browser. If that doesn't work, come back at a later time. If the problem persists, you can seek help in the [Lemmy support community](https://lemmy.ml/c/lemmy_support) or [Lemmy Matrix room](https://lemmy.ml/c/lemmy_support).
> If you would like to reach out to one of Lemmy admins for support, try the following Matrix addresses:
>    @happydooby:matrix.org
>    @nutomic:matrix.org
> The server returned this error: couldnt_find_post. This may be useful for admins and developers to diagnose and fix the error
![image](https://github.com/user-attachments/assets/c60c5925-107d-4852-aba8-4c4b087c9d53)

### Steps to Reproduce

1. Go to https://lemmy.ml/
2. Click on "What is Lemmy.ml" in the right "Lemmy" sidebar
3. Get redirected to https://lemmy.ml/post/70280
4. See the error: `couldnt_find_post`

### Technical Details

Browser console says `GET https://lemmy.ml/post/70280` responded with HTTP status 500.  Looking at the network tab and the raw HTTP requests / responses, it appears the error page is generated by the backend.

### Version

BE: 0.19.8

### Lemmy Instance URL

lemmy.ml


Discussion / hints:

Fix patch:
diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs
index fc2fbf0d3f..52e0363769 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 4f28aaa32e..f1ce64d496 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::<diesel::result::Error>() {
           Some(diesel::result::Error::NotFound) => actix_web::http::StatusCode::NOT_FOUND,
           _ => actix_web::http::StatusCode::BAD_REQUEST,


Test patch: