fix(backend): handle ecto errors when fetching and create entities

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2023-12-05 08:06:16 +01:00
parent f1084c101f
commit 89d1ee42f4
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -42,7 +42,7 @@ defmodule Mobilizon.Federation.ActivityPub.Fetcher do
end end
@spec fetch_and_create(String.t(), Keyword.t()) :: @spec fetch_and_create(String.t(), Keyword.t()) ::
{:ok, map(), struct()} | {:error, atom()} | :error {:ok, map(), struct()} | {:error, atom()} | {:error, Ecto.Changeset.t()} | :error
def fetch_and_create(url, options \\ []) do def fetch_and_create(url, options \\ []) do
case fetch(url, options) do case fetch(url, options) do
{:ok, data} when is_map(data) -> {:ok, data} when is_map(data) ->
@ -61,6 +61,9 @@ defmodule Mobilizon.Federation.ActivityPub.Fetcher do
{:error, error} when is_atom(error) -> {:error, error} when is_atom(error) ->
{:error, error} {:error, error}
{:error, %Ecto.Changeset{} = err} ->
{:error, err}
:error -> :error ->
{:error, :transmogrifier_error} {:error, :transmogrifier_error}
end end