Improve AP error handling

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-04-28 18:06:17 +02:00
parent 3163c22c4f
commit 4fd6ecf53d
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 17 additions and 1 deletions

View File

@ -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}

View File

@ -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}

View File

@ -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