Bring our adjustments into line with atom-failure

This commit is contained in:
Floatingghost 2024-04-13 22:56:04 +01:00
parent 49ed27cd96
commit 33fb74043d
3 changed files with 24 additions and 16 deletions

View file

@ -68,7 +68,10 @@ defmodule Akkoma.Collections.Fetcher do
items
end
else
{:error, {"Object has been deleted", _, _}} ->
{:error, :not_found} ->
items
{:error, :forbidden} ->
items
{:error, error} ->

View file

@ -122,7 +122,7 @@ defmodule Pleroma.Object.Fetcher do
{:ok, object}
else
{:local, true} -> {:ok, object}
{:id, false} -> {:error, "Object id changed on refetch"}
{:id, false} -> {:error, :id_mismatch}
e -> {:error, e}
end
end
@ -136,7 +136,7 @@ defmodule Pleroma.Object.Fetcher do
def fetch_object_from_id(id, options \\ []) do
with %URI{} = uri <- URI.parse(id),
# let's check the URI is even vaguely valid first
{:scheme, true} <- {:scheme, uri.scheme == "http" or uri.scheme == "https"},
{:valid_uri_scheme, true} <- {:valid_uri_scheme, uri.scheme == "http" or uri.scheme == "https"},
# If we have instance restrictions, apply them here to prevent fetching from unwanted instances
{:ok, nil} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_reject(uri),
{:ok, _} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_accept(uri),
@ -155,8 +155,9 @@ defmodule Pleroma.Object.Fetcher do
log_fetch_error(id, e)
{:error, :allowed_depth}
{:scheme, false} ->
{:error, "URI Scheme Invalid"}
{:valid_uri_scheme, _} = e ->
log_fetch_error(id, e)
{:error, :invalid_uri_scheme}
{:containment, reason} = e ->
log_fetch_error(id, e)
@ -253,7 +254,7 @@ defmodule Pleroma.Object.Fetcher do
def fetch_and_contain_remote_object_from_id(id) when is_binary(id) do
Logger.debug("Fetching object #{id} via AP")
with {:scheme, true} <- {:scheme, String.starts_with?(id, "http")},
with {:valid_uri_scheme, true} <- {:valid_uri_scheme, String.starts_with?(id, "http")},
{_, :ok} <- {:local_fetch, Containment.contain_local_fetch(id)},
{:ok, final_id, body} <- get_object(id),
{:ok, data} <- safe_json_decode(body),
@ -265,17 +266,21 @@ defmodule Pleroma.Object.Fetcher do
{:ok, data}
else
{:strict_id, _} ->
{:error, "Object's ActivityPub id/url does not match final fetch URL"}
{:strict_id, _} = e->
log_fetch_error(id, e)
{:error, :id_mismatch}
{:scheme, _} ->
{:error, "Unsupported URI scheme"}
{:valid_uri_scheme, _} = e ->
log_fetch_error(id, e)
{:error, :invalid_uri_scheme}
{:local_fetch, _} ->
{:error, "Trying to fetch local resource"}
{:local_fetch, _} = e ->
log_fetch_error(id, e)
{:error, :local_resource}
{:containment, _} ->
{:error, "Object containment failed."}
{:containment, reason} ->
log_fetch_error(id, reason)
{:error, reason}
{:error, e} ->
{:error, e}
@ -286,7 +291,7 @@ defmodule Pleroma.Object.Fetcher do
end
def fetch_and_contain_remote_object_from_id(_id),
do: {:error, "id must be a string"}
do: {:error, :invalid_id}
defp check_crossdomain_redirect(final_host, original_url)

View file

@ -570,7 +570,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "returns nil when cannot normalize object" do
assert capture_log(fn ->
refute Transmogrifier.get_obj_helper("test-obj-id")
end) =~ "URI Scheme Invalid"
end) =~ ":valid_uri_scheme"
end
@tag capture_log: true