Handle incoming Creates better
This commit is contained in:
parent
2316c5d41d
commit
9e39d56325
|
@ -13,11 +13,25 @@ defmodule Clacks.Inbox do
|
|||
Repo.insert(changeset)
|
||||
end
|
||||
|
||||
@spec handle_create(activity :: map()) :: :ok | {:error, reason :: any()}
|
||||
def handle_create(%{"type" => "Create", "object" => object} = activity) do
|
||||
changeset = Object.changeset(%Object{}, %{data: object})
|
||||
{:ok, _object} = Repo.insert(changeset)
|
||||
|
||||
{:ok, _activity} = store_activity(activity)
|
||||
case Repo.insert(changeset) do
|
||||
{:error, changeset} ->
|
||||
Logger.error("Couldn't store object: #{inspect(changeset)}")
|
||||
{:error, "Couldn't store changeset"}
|
||||
|
||||
{:ok, _object} ->
|
||||
case store_activity(activity) do
|
||||
{:error, changeset} ->
|
||||
Logger.error("Couldn't store Create activity: #{inspect(changeset)}")
|
||||
{:error, "Couldn't store Create activity"}
|
||||
|
||||
{:ok, _activity} ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@spec handle_follow(activity :: map()) :: :ok | {:error, reason :: any()}
|
||||
|
|
|
@ -15,10 +15,17 @@ defmodule ClacksWeb.InboxController do
|
|||
end
|
||||
|
||||
def handle(conn, %{"type" => "Create"} = activity) do
|
||||
Inbox.handle_create(activity)
|
||||
case Inbox.handle_create(activity) do
|
||||
:ok ->
|
||||
conn
|
||||
|> put_status(200)
|
||||
|
||||
conn
|
||||
|> put_status(200)
|
||||
{:error, reason} ->
|
||||
Logger.error("Could not handle incoming Create: #{inspect(reason)}")
|
||||
|
||||
conn
|
||||
|> put_status(500)
|
||||
end
|
||||
|> json(%{})
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue