Leverage existing atoms as return errors for the object fetcher
This commit is contained in:
parent
53a9413b95
commit
7e5004b3e2
4 changed files with 9 additions and 11 deletions
|
@ -351,10 +351,10 @@ def get_object(id) do
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
{:ok, %{status: 403}} ->
|
{:ok, %{status: 403}} ->
|
||||||
{:error, "Object fetch has been denied"}
|
{:error, :forbidden}
|
||||||
|
|
||||||
{:ok, %{status: code}} when code in [404, 410] ->
|
{:ok, %{status: code}} when code in [404, 410] ->
|
||||||
{:error, {"Object has been deleted", id, code}}
|
{:error, :not_found}
|
||||||
|
|
||||||
{:error, e} ->
|
{:error, e} ->
|
||||||
{:error, e}
|
{:error, e}
|
||||||
|
|
|
@ -15,11 +15,11 @@ def perform(%Job{args: %{"op" => "fetch_remote", "id" => id} = args}) do
|
||||||
{:ok, _object} ->
|
{:ok, _object} ->
|
||||||
:ok
|
:ok
|
||||||
|
|
||||||
{:error, reason = "Object fetch has been denied"} ->
|
{:error, :forbidden} ->
|
||||||
{:cancel, reason}
|
{:cancel, :forbidden}
|
||||||
|
|
||||||
{:error, reason = "Object has been deleted"} ->
|
{:error, :not_found} ->
|
||||||
{:cancel, reason}
|
{:cancel, :not_found}
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
:error
|
:error
|
||||||
|
|
|
@ -404,16 +404,14 @@ test "all objects with fake directions are rejected by the object fetcher" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "handle HTTP 410 Gone response" do
|
test "handle HTTP 410 Gone response" do
|
||||||
assert {:error,
|
assert {:error, :not_found} ==
|
||||||
{"Object has been deleted", "https://mastodon.example.org/users/userisgone", 410}} ==
|
|
||||||
Fetcher.fetch_and_contain_remote_object_from_id(
|
Fetcher.fetch_and_contain_remote_object_from_id(
|
||||||
"https://mastodon.example.org/users/userisgone"
|
"https://mastodon.example.org/users/userisgone"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "handle HTTP 404 response" do
|
test "handle HTTP 404 response" do
|
||||||
assert {:error,
|
assert {:error, :not_found} ==
|
||||||
{"Object has been deleted", "https://mastodon.example.org/users/userisgone404", 404}} ==
|
|
||||||
Fetcher.fetch_and_contain_remote_object_from_id(
|
Fetcher.fetch_and_contain_remote_object_from_id(
|
||||||
"https://mastodon.example.org/users/userisgone404"
|
"https://mastodon.example.org/users/userisgone404"
|
||||||
)
|
)
|
||||||
|
|
|
@ -132,7 +132,7 @@ test "show follow page with error when user can not be fetched by `acct` link",
|
||||||
|> html_response(200)
|
|> html_response(200)
|
||||||
|
|
||||||
assert response =~ "Error fetching user"
|
assert response =~ "Error fetching user"
|
||||||
end) =~ "Object has been deleted"
|
end) =~ ":not_found"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue