Return a proper error directly when a group name conflicts

And translate the error

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-03-24 16:21:30 +01:00 committed by tykayn
parent 29062ff883
commit c2f0ee7928

View File

@ -5,9 +5,10 @@ defmodule Mobilizon.GraphQL.API.Groups do
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.GraphQL.Error
alias Mobilizon.Federation.ActivityPub.{Actions, Activity} alias Mobilizon.Federation.ActivityPub.{Actions, Activity}
alias Mobilizon.Service.Formatter.HTML alias Mobilizon.Service.Formatter.HTML
import Mobilizon.Web.Gettext
@doc """ @doc """
Create a group Create a group
@ -26,7 +27,13 @@ defmodule Mobilizon.GraphQL.API.Groups do
Actions.Create.create(:actor, args, true, %{"actor" => args.creator_actor.url}) Actions.Create.create(:actor, args, true, %{"actor" => args.creator_actor.url})
%Actor{} -> %Actor{} ->
{:error, "A profile or group with that name already exists"} {:error,
%Error{
code: :validation,
message: dgettext("errors", "A profile or group with that name already exists"),
status_code: 409,
field: "preferred_username"
}}
end end
end end