Remove Fetcher.fetch_object_from_id!/2
It was only being called once and can be replaced with a case statement.
This commit is contained in:
parent
5f1d707367
commit
ea0ec5fbcf
|
@ -177,7 +177,10 @@ def normalize(ap_id, options) when is_binary(ap_id) do
|
||||||
ap_id
|
ap_id
|
||||||
|
|
||||||
Keyword.get(options, :fetch) ->
|
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 ->
|
true ->
|
||||||
get_cached_by_ap_id(ap_id)
|
get_cached_by_ap_id(ap_id)
|
||||||
|
|
|
@ -79,9 +79,11 @@ def fetch_object_from_id(id, options \\ []) do
|
||||||
{:error, "Object containment failed."}
|
{:error, "Object containment failed."}
|
||||||
|
|
||||||
{:transmogrifier, {:error, {:reject, e}}} ->
|
{:transmogrifier, {:error, {:reject, e}}} ->
|
||||||
|
Logger.info("Rejected #{id} while fetching: #{inspect(e)}")
|
||||||
{:reject, e}
|
{:reject, e}
|
||||||
|
|
||||||
{:transmogrifier, {:reject, e}} ->
|
{:transmogrifier, {:reject, e}} ->
|
||||||
|
Logger.info("Rejected #{id} while fetching: #{inspect(e)}")
|
||||||
{:reject, e}
|
{:reject, e}
|
||||||
|
|
||||||
{:transmogrifier, _} = e ->
|
{:transmogrifier, _} = e ->
|
||||||
|
@ -97,10 +99,12 @@ def fetch_object_from_id(id, options \\ []) do
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
|
|
||||||
{:fetch, {:error, error}} ->
|
{:fetch, {:error, error}} ->
|
||||||
|
Logger.error("Error while fetching #{id}: #{inspect(error)}")
|
||||||
{:error, error}
|
{:error, error}
|
||||||
|
|
||||||
e ->
|
e ->
|
||||||
e
|
Logger.error("Error while fetching #{id}: #{inspect(e)}")
|
||||||
|
{:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -117,26 +121,6 @@ defp prepare_activity_params(data) do
|
||||||
|> Maps.put_if_present("bcc", data["bcc"])
|
|> Maps.put_if_present("bcc", data["bcc"])
|
||||||
end
|
end
|
||||||
|
|
||||||
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"} ->
|
|
||||||
nil
|
|
||||||
|
|
||||||
{:reject, reason} ->
|
|
||||||
Logger.info("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
|
defp make_signature(id, date) do
|
||||||
uri = URI.parse(id)
|
uri = URI.parse(id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue