Catch 404s.

This commit is contained in:
Phil Hagelberg 2019-11-04 22:56:51 -08:00
parent df2f59be91
commit 828259fb65

View file

@ -61,7 +61,8 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
end end
def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do
activity = Activity.get_by_id_with_object(notice_id) case Activity.get_by_id_with_object(notice_id) do
%Activity{} = activity ->
timeline = timeline =
activity.object.data["context"] activity.object.data["context"]
|> ActivityPub.fetch_activities_for_context(%{}) |> ActivityPub.fetch_activities_for_context(%{})
@ -69,11 +70,17 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|> Enum.map(&represent(&1, &1.object.id == activity.object.id)) |> Enum.map(&represent(&1, &1.object.id == activity.object.id))
render(conn, "conversation.html", %{activities: timeline}) render(conn, "conversation.html", %{activities: timeline})
_ ->
conn
|> put_status(404)
|> render_error(:not_found, "Notice not found")
end
end end
def show(%{assigns: %{username_or_id: username_or_id}} = conn, params) do def show(%{assigns: %{username_or_id: username_or_id}} = conn, params) do
%User{} = user = User.get_cached_by_nickname_or_id(username_or_id) case User.get_cached_by_nickname_or_id(username_or_id) do
%User{} = user ->
timeline = timeline =
ActivityPub.fetch_user_activities(user, nil, Map.take(params, @page_keys)) ActivityPub.fetch_user_activities(user, nil, Map.take(params, @page_keys))
|> Enum.map(&represent/1) |> Enum.map(&represent/1)
@ -90,6 +97,12 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
prev_page_id: prev_page_id, prev_page_id: prev_page_id,
next_page_id: next_page_id next_page_id: next_page_id
}) })
_ ->
conn
|> put_status(404)
|> render_error(:not_found, "User not found")
end
end end
def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts), def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),