fixed connection dying error

This commit is contained in:
Moon Man 2024-08-29 17:57:17 +00:00
parent fcbd2e9472
commit cd26855661
2 changed files with 11 additions and 6 deletions

View File

@ -22,7 +22,7 @@ defmodule Vonbraun.ActivityPub.Handler do
@spec handle(%{type: String.t()}, map()) :: :ok | {:ok, atom()} | {:error, any()}
def handle(activity = %{"type" => type}, actor = %{}) when is_binary(type) do
Agent.get(__MODULE__, fn map ->
func = Map.get(map, type, fn _ -> {:error, :type} end)
func = Map.get(map, type, fn _, _ -> {:ok, :type} end)
apply(func, [activity, actor])
end)
end

View File

@ -19,7 +19,7 @@ defmodule Vonbraun.InboxRouter do
end
post "/" do
{:ok, body, _conn} = Plug.Conn.read_body(conn)
{:ok, body, conn} = Plug.Conn.read_body(conn)
Logger.debug("Got inbox POST: #{body}")
cond do
@ -51,19 +51,24 @@ defmodule Vonbraun.InboxRouter do
200
end
send_resp(conn, status_code, "boop")
Logger.debug("Sending reply...")
conn = send_resp(conn, status_code, "boop")
halt(conn)
else
{:actor_url, {:ok, %{"type" => "Delete"}}} ->
Logger.debug("Ignoring deletes right now.")
send_resp(conn, 200, "boop")
conn = send_resp(conn, 200, "boop")
halt(conn)
error ->
Logger.warning("Some kind of failure: #{inspect(error)}")
send_resp(conn, 500, "I fucked up")
conn = send_resp(conn, 500, "I fucked up")
halt(conn)
end
true ->
send_resp(conn, 404, "fuck off")
conn = send_resp(conn, 404, "fuck off")
halt(conn)
end
end
end