Handle failed fetches a bit better #743
2 changed files with 9 additions and 23 deletions
|
@ -178,7 +178,10 @@ def normalize(ap_id, options) when is_binary(ap_id) do
|
|||
ap_id
|
||||
|
||||
Keyword.get(options, :fetch) ->
|
||||
Fetcher.fetch_object_from_id!(ap_id, options)
|
||||
case Fetcher.fetch_object_from_id(ap_id, options) do
|
||||
{:ok, object} -> object
|
||||
_ -> nil
|
||||
end
|
||||
|
||||
true ->
|
||||
get_cached_by_ap_id(ap_id)
|
||||
|
|
|
@ -158,9 +158,11 @@ def fetch_object_from_id(id, options \\ []) do
|
|||
{:error, "URI Scheme Invalid"}
|
||||
|
||||
{:transmogrifier, {:error, {:reject, e}}} ->
|
||||
Logger.info("Rejected #{id} while fetching: #{inspect(e)}")
|
||||
{:reject, e}
|
||||
|
||||
{:transmogrifier, {:reject, e}} ->
|
||||
Logger.info("Rejected #{id} while fetching: #{inspect(e)}")
|
||||
{:reject, e}
|
||||
|
||||
{:transmogrifier, _} = e ->
|
||||
|
@ -176,13 +178,15 @@ def fetch_object_from_id(id, options \\ []) do
|
|||
{:ok, object}
|
||||
|
||||
{:fetch, {:error, error}} ->
|
||||
Logger.error("Error while fetching #{id}: #{inspect(error)}")
|
||||
{:error, error}
|
||||
|
||||
{:reject, reason} ->
|
||||
{:reject, reason}
|
||||
|
||||
e ->
|
||||
e
|
||||
Logger.error("Error while fetching #{id}: #{inspect(e)}")
|
||||
{:error, e}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -199,27 +203,6 @@ defp prepare_activity_params(data) do
|
|||
|> Maps.put_if_present("bcc", data["bcc"])
|
||||
end
|
||||
|
||||
@doc "Identical to `fetch_object_from_id/2` but just directly returns the object or on error `nil`"
|
||||
def fetch_object_from_id!(id, options \\ []) do
|
||||
with {:ok, object} <- fetch_object_from_id(id, options) do
|
||||
object
|
||||
else
|
||||
{:error, %Tesla.Mock.Error{}} ->
|
||||
nil
|
||||
|
||||
{:error, {"Object has been deleted", _id, _code}} ->
|
||||
nil
|
||||
|
||||
{:reject, reason} ->
|
||||
Logger.debug("Rejected #{id} while fetching: #{inspect(reason)}")
|
||||
nil
|
||||
|
||||
e ->
|
||||
Logger.error("Error while fetching #{id}: #{inspect(e)}")
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
defp make_signature(id, date) do
|
||||
uri = URI.parse(id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue