Better error handling for ActivityPubController

This commit is contained in:
lain 2018-06-03 19:58:59 +02:00
parent 4856ba596f
commit 06439f64d0
3 changed files with 11 additions and 8 deletions

View file

@ -27,9 +27,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|> json(ObjectView.render("object.json", %{object: object}))
else
{:public?, false} ->
conn
|> put_status(404)
|> json("Not found")
{:error, :not_found}
end
end
@ -107,6 +105,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
json(conn, "ok")
end
def errors(conn, {:error, :not_found}) do
conn
|> put_status(404)
|> json("Not found")
end
def errors(conn, _e) do
conn
|> put_status(500)

View file

@ -9,12 +9,12 @@ defmodule Pleroma.Web.OStatus.OStatusController do
alias Pleroma.Web.ActivityPub.ActivityPubController
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)
case get_format(conn) do
"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))
end
end
@ -68,9 +68,9 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|> send_resp(200, "")
end
def object(conn, %{"uuid" => uuid} = params) do
def object(conn, %{"uuid" => uuid}) do
if get_format(conn) == "activity+json" do
ActivityPubController.object(conn, params)
ActivityPubController.call(conn, :object)
else
with id <- o_status_url(conn, :object, uuid),
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),

View file

@ -4,7 +4,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
alias Pleroma.{Repo, User}
alias Pleroma.Activity
alias Pleroma.Web.CommonAPI
describe "/users/:nickname" do
test "it returns a json representation of the user", %{conn: conn} do