mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-24 18:15:19 +00:00
Better error handling for ActivityPubController
This commit is contained in:
parent
4856ba596f
commit
06439f64d0
|
@ -27,9 +27,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
||||||
|> json(ObjectView.render("object.json", %{object: object}))
|
|> json(ObjectView.render("object.json", %{object: object}))
|
||||||
else
|
else
|
||||||
{:public?, false} ->
|
{:public?, false} ->
|
||||||
conn
|
{:error, :not_found}
|
||||||
|> put_status(404)
|
|
||||||
|> json("Not found")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -107,6 +105,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
||||||
json(conn, "ok")
|
json(conn, "ok")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def errors(conn, {:error, :not_found}) do
|
||||||
|
conn
|
||||||
|
|> put_status(404)
|
||||||
|
|> json("Not found")
|
||||||
|
end
|
||||||
|
|
||||||
def errors(conn, _e) do
|
def errors(conn, _e) do
|
||||||
conn
|
conn
|
||||||
|> put_status(500)
|
|> put_status(500)
|
||||||
|
|
|
@ -9,12 +9,12 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPubController
|
alias Pleroma.Web.ActivityPub.ActivityPubController
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
|
||||||
def feed_redirect(conn, %{"nickname" => nickname} = params) do
|
def feed_redirect(conn, %{"nickname" => nickname}) do
|
||||||
user = User.get_cached_by_nickname(nickname)
|
user = User.get_cached_by_nickname(nickname)
|
||||||
|
|
||||||
case get_format(conn) do
|
case get_format(conn) do
|
||||||
"html" -> Fallback.RedirectController.redirector(conn, nil)
|
"html" -> Fallback.RedirectController.redirector(conn, nil)
|
||||||
"activity+json" -> ActivityPubController.user(conn, params)
|
"activity+json" -> ActivityPubController.call(conn, :user)
|
||||||
_ -> redirect(conn, external: OStatus.feed_path(user))
|
_ -> redirect(conn, external: OStatus.feed_path(user))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -68,9 +68,9 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
||||||
|> send_resp(200, "")
|
|> send_resp(200, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def object(conn, %{"uuid" => uuid} = params) do
|
def object(conn, %{"uuid" => uuid}) do
|
||||||
if get_format(conn) == "activity+json" do
|
if get_format(conn) == "activity+json" do
|
||||||
ActivityPubController.object(conn, params)
|
ActivityPubController.call(conn, :object)
|
||||||
else
|
else
|
||||||
with id <- o_status_url(conn, :object, uuid),
|
with id <- o_status_url(conn, :object, uuid),
|
||||||
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),
|
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),
|
||||||
|
|
|
@ -4,7 +4,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||||
alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
|
alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
|
||||||
alias Pleroma.{Repo, User}
|
alias Pleroma.{Repo, User}
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Web.CommonAPI
|
|
||||||
|
|
||||||
describe "/users/:nickname" do
|
describe "/users/:nickname" do
|
||||||
test "it returns a json representation of the user", %{conn: conn} do
|
test "it returns a json representation of the user", %{conn: conn} do
|
||||||
|
|
Loading…
Reference in a new issue