From cd26855661b9d391976e61582182c17b30d4b423 Mon Sep 17 00:00:00 2001 From: Moon Man Date: Thu, 29 Aug 2024 17:57:17 +0000 Subject: [PATCH] fixed connection dying error --- lib/vonbraun/activity_pub/handler.ex | 2 +- lib/vonbraun/inbox_router.ex | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/vonbraun/activity_pub/handler.ex b/lib/vonbraun/activity_pub/handler.ex index c9df419..a41fdf8 100644 --- a/lib/vonbraun/activity_pub/handler.ex +++ b/lib/vonbraun/activity_pub/handler.ex @@ -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 diff --git a/lib/vonbraun/inbox_router.ex b/lib/vonbraun/inbox_router.ex index 5fafafe..d0e8fc2 100644 --- a/lib/vonbraun/inbox_router.ex +++ b/lib/vonbraun/inbox_router.ex @@ -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