Leverage existing atoms as return errors for the object fetcher

This commit is contained in:
Mark Felder 2023-12-27 21:57:47 -05:00 committed by Floatingghost
parent 53a9413b95
commit 7e5004b3e2
4 changed files with 9 additions and 11 deletions

View file

@ -351,10 +351,10 @@ defmodule Pleroma.Object.Fetcher do
end
else
{:ok, %{status: 403}} ->
{:error, "Object fetch has been denied"}
{:error, :forbidden}
{:ok, %{status: code}} when code in [404, 410] ->
{:error, {"Object has been deleted", id, code}}
{:error, :not_found}
{:error, e} ->
{:error, e}

View file

@ -15,11 +15,11 @@ defmodule Pleroma.Workers.RemoteFetcherWorker do
{:ok, _object} ->
:ok
{:error, reason = "Object fetch has been denied"} ->
{:cancel, reason}
{:error, :forbidden} ->
{:cancel, :forbidden}
{:error, reason = "Object has been deleted"} ->
{:cancel, reason}
{:error, :not_found} ->
{:cancel, :not_found}
_ ->
:error

View file

@ -404,16 +404,14 @@ defmodule Pleroma.Object.FetcherTest do
end
test "handle HTTP 410 Gone response" do
assert {:error,
{"Object has been deleted", "https://mastodon.example.org/users/userisgone", 410}} ==
assert {:error, :not_found} ==
Fetcher.fetch_and_contain_remote_object_from_id(
"https://mastodon.example.org/users/userisgone"
)
end
test "handle HTTP 404 response" do
assert {:error,
{"Object has been deleted", "https://mastodon.example.org/users/userisgone404", 404}} ==
assert {:error, :not_found} ==
Fetcher.fetch_and_contain_remote_object_from_id(
"https://mastodon.example.org/users/userisgone404"
)

View file

@ -132,7 +132,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|> html_response(200)
assert response =~ "Error fetching user"
end) =~ "Object has been deleted"
end) =~ ":not_found"
end
end