mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-25 09:22:22 +00:00
f3d37325fa
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
25 lines
615 B
Elixir
25 lines
615 B
Elixir
defmodule MobilizonWeb.Schema.Utils do
|
|
@moduledoc """
|
|
Helper functions for MobilizonWeb.Schema
|
|
"""
|
|
|
|
def handle_errors(fun) do
|
|
fn source, args, info ->
|
|
case Absinthe.Resolution.call(fun, source, args, info) do
|
|
{:error, %Ecto.Changeset{} = changeset} -> format_changeset(changeset)
|
|
val -> val
|
|
end
|
|
end
|
|
end
|
|
|
|
def format_changeset(changeset) do
|
|
# {:error, [email: {"has already been taken", []}]}
|
|
errors =
|
|
changeset.errors
|
|
|> Enum.map(fn {key, {value, _context}} ->
|
|
[message: "#{value}", details: key]
|
|
end)
|
|
|
|
{:error, errors}
|
|
end
|
|
end
|