1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-23 08:22:50 +00:00
mobilizon/lib/graphql/helpers/error.ex

26 lines
619 B
Elixir
Raw Normal View History

2020-01-26 19:34:25 +00:00
defmodule Mobilizon.GraphQL.Helpers.Error do
@moduledoc """
2020-01-26 19:34:25 +00:00
Helper functions for Mobilizon.GraphQL
"""
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