From 4fd6ecf53d0410d0922e6872a64406cb17e2cfbb Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 28 Apr 2021 18:06:17 +0200 Subject: [PATCH] Improve AP error handling Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/activity_pub.ex | 4 ++++ lib/federation/activity_pub/actor.ex | 6 +++++- lib/federation/activity_pub/refresher.ex | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index a46a02cb..66ffe52f 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -101,6 +101,10 @@ defmodule Mobilizon.Federation.ActivityPub do {:existing, entity} -> handle_existing_entity(url, entity, options) + {:error, e} -> + Logger.warn("Something failed while fetching url #{inspect(e)}") + {:error, e} + e -> Logger.warn("Something failed while fetching url #{inspect(e)}") {:error, e} diff --git a/lib/federation/activity_pub/actor.ex b/lib/federation/activity_pub/actor.ex index aad2f2f6..0cc3b589 100644 --- a/lib/federation/activity_pub/actor.ex +++ b/lib/federation/activity_pub/actor.ex @@ -48,7 +48,8 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do @doc """ Create an actor locally by its URL (AP ID) """ - @spec make_actor_from_url(String.t(), boolean()) :: {:ok, %Actor{}} | {:error, any()} + @spec make_actor_from_url(String.t(), boolean()) :: + {:ok, %Actor{}} | {:error, :actor_deleted} | {:error, :http_error} | {:error, any()} def make_actor_from_url(url, preload \\ false) do if are_same_origin?(url, Endpoint.url()) do {:error, "Can't make a local actor from URL"} @@ -62,6 +63,9 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do Logger.info("Actor was deleted") {:error, :actor_deleted} + {:error, :http_error} -> + {:error, :http_error} + {:error, e} -> Logger.warn("Failed to make actor from url") {:error, e} diff --git a/lib/federation/activity_pub/refresher.ex b/lib/federation/activity_pub/refresher.ex index dec99842..8c466838 100644 --- a/lib/federation/activity_pub/refresher.ex +++ b/lib/federation/activity_pub/refresher.ex @@ -60,6 +60,12 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do :ok <- fetch_collection(events_url, on_behalf_of) do :ok else + {:error, :actor_deleted} -> + {:error, :actor_deleted} + + {:error, :http_error} -> + {:error, :http_error} + {:error, err} -> Logger.error("Error while refreshing a group") @@ -68,6 +74,7 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do ) Logger.debug(inspect(err)) + {:error, err} err -> Logger.error("Error while refreshing a group") @@ -77,6 +84,7 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do ) Logger.debug(inspect(err)) + err end end