Merge branch 'fix-sentry-issues' into 'master'

Improve AP error handling

See merge request framasoft/mobilizon!918
This commit is contained in:
Thomas Citharel 2021-04-29 08:55:40 +00:00
commit 63fdfc7190
7 changed files with 23 additions and 7 deletions

View File

@ -270,7 +270,7 @@ config :mobilizon, Oban,
{Oban.Plugins.Cron, {Oban.Plugins.Cron,
crontab: [ crontab: [
{"@hourly", Mobilizon.Service.Workers.BuildSiteMap, queue: :background}, {"@hourly", Mobilizon.Service.Workers.BuildSiteMap, queue: :background},
{"17 * * * *", Mobilizon.Service.Workers.RefreshGroups, queue: :background}, {"17 4 * * *", Mobilizon.Service.Workers.RefreshGroups, queue: :background},
# To be activated in Mobilizon 1.2 # To be activated in Mobilizon 1.2
# {"@hourly", Mobilizon.Service.Workers.CleanOrphanMediaWorker, queue: :background}, # {"@hourly", Mobilizon.Service.Workers.CleanOrphanMediaWorker, queue: :background},
{"@hourly", Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker, queue: :background}, {"@hourly", Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker, queue: :background},

View File

@ -101,8 +101,12 @@ defmodule Mobilizon.Federation.ActivityPub do
{:existing, entity} -> {:existing, entity} ->
handle_existing_entity(url, entity, options) handle_existing_entity(url, entity, options)
{:error, e} ->
Logger.warn("Something failed while fetching url #{url} #{inspect(e)}")
{:error, e}
e -> e ->
Logger.warn("Something failed while fetching url #{inspect(e)}") Logger.warn("Something failed while fetching url #{url} #{inspect(e)}")
{:error, e} {:error, e}
end end
end end

View File

@ -48,7 +48,8 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do
@doc """ @doc """
Create an actor locally by its URL (AP ID) 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 def make_actor_from_url(url, preload \\ false) do
if are_same_origin?(url, Endpoint.url()) do if are_same_origin?(url, Endpoint.url()) do
{:error, "Can't make a local actor from URL"} {:error, "Can't make a local actor from URL"}
@ -62,6 +63,9 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do
Logger.info("Actor was deleted") Logger.info("Actor was deleted")
{:error, :actor_deleted} {:error, :actor_deleted}
{:error, :http_error} ->
{:error, :http_error}
{:error, e} -> {:error, e} ->
Logger.warn("Failed to make actor from url") Logger.warn("Failed to make actor from url")
{:error, e} {:error, e}

View File

@ -60,6 +60,12 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do
:ok <- fetch_collection(events_url, on_behalf_of) do :ok <- fetch_collection(events_url, on_behalf_of) do
:ok :ok
else else
{:error, :actor_deleted} ->
{:error, :actor_deleted}
{:error, :http_error} ->
{:error, :http_error}
{:error, err} -> {:error, err} ->
Logger.error("Error while refreshing a group") Logger.error("Error while refreshing a group")
@ -68,6 +74,7 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do
) )
Logger.debug(inspect(err)) Logger.debug(inspect(err))
{:error, err}
err -> err ->
Logger.error("Error while refreshing a group") Logger.error("Error while refreshing a group")
@ -77,6 +84,7 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do
) )
Logger.debug(inspect(err)) Logger.debug(inspect(err))
err
end end
end end

View File

@ -111,8 +111,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
{:ok, activity, event} {:ok, activity, event}
else else
{:existing_event, %Event{} = event} -> {:ok, nil, event} {:existing_event, %Event{} = event} -> {:ok, nil, event}
{:error, _, _} -> :error _ -> :error
{:error, _} -> :error
end end
end end

View File

@ -126,6 +126,7 @@ defmodule Mobilizon.Discussions.Comment do
|> put_assoc(:media, Map.get(attrs, :media, [])) |> put_assoc(:media, Map.get(attrs, :media, []))
|> put_tags(attrs) |> put_tags(attrs)
|> put_mentions(attrs) |> put_mentions(attrs)
|> unique_constraint(:url, name: :comments_url_index)
end end
@spec maybe_generate_uuid(Ecto.Changeset.t()) :: Ecto.Changeset.t() @spec maybe_generate_uuid(Ecto.Changeset.t()) :: Ecto.Changeset.t()

View File

@ -36,7 +36,7 @@ defmodule Mobilizon.Events.Tag do
|> TitleSlug.maybe_generate_slug() |> TitleSlug.maybe_generate_slug()
|> validate_required(@required_attrs) |> validate_required(@required_attrs)
|> TitleSlug.unique_constraint() |> TitleSlug.unique_constraint()
|> validate_length(:title, min: 2, max: 20) |> validate_length(:title, min: 2, max: 40)
|> validate_length(:slug, min: 2, max: 20) |> validate_length(:slug, min: 2, max: 40)
end end
end end