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
parent 93425108c5
commit cd3c316881
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

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