Add a proper error message when adding an instance that doesn't respond

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2022-05-06 13:06:41 +02:00
parent 6a937d6ede
commit cd3d0c5fc4
82 changed files with 8792 additions and 8199 deletions

View File

@@ -489,15 +489,25 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
{:error, :unauthenticated}
end
@spec create_instance(any, map(), Absinthe.Resolution.t()) ::
{:error, atom() | binary()}
| {:ok, Mobilizon.Instances.Instance.t()}
def create_instance(
parent,
%{domain: domain} = args,
%{context: %{current_user: %User{role: role}}} = resolution
)
when is_admin(role) do
with {:ok, _activity, _follow} <- Relay.follow(domain) do
Instances.refresh()
get_instance(parent, args, resolution)
case Relay.follow(domain) do
{:ok, _activity, _follow} ->
Instances.refresh()
get_instance(parent, args, resolution)
{:error, :http_error} ->
{:error, dgettext("errors", "Unable to find an instance to follow at this address")}
{:error, err} ->
{:error, err}
end
end