Handle Webfinger endpoint not returning 200

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-11-15 08:47:03 +01:00
parent 3f9e1c8e19
commit b547f1f1ee
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -188,10 +188,12 @@ defmodule Mobilizon.Federation.WebFinger do
@spec find_webfinger_endpoint(String.t()) :: @spec find_webfinger_endpoint(String.t()) ::
{:ok, String.t()} | {:error, :link_not_found} | {:error, any()} {:ok, String.t()} | {:error, :link_not_found} | {:error, any()}
defp find_webfinger_endpoint(domain) when is_binary(domain) do defp find_webfinger_endpoint(domain) when is_binary(domain) do
with {:ok, %{body: body}} <- fetch_document("http://#{domain}/.well-known/host-meta"), with {:ok, %Tesla.Env{status: 200, body: body}} <-
fetch_document("http://#{domain}/.well-known/host-meta"),
link_template when is_binary(link_template) <- find_link_from_template(body) do link_template when is_binary(link_template) <- find_link_from_template(body) do
{:ok, link_template} {:ok, link_template}
else else
{:ok, %Tesla.Env{status: 404}} -> {:error, :entity_not_found}
{:error, :link_not_found} -> {:error, :link_not_found} {:error, :link_not_found} -> {:error, :link_not_found}
{:error, error} -> {:error, error} {:error, error} -> {:error, error}
end end