mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-24 08:54:08 +00:00
559c889f1b
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
22 lines
627 B
Elixir
22 lines
627 B
Elixir
defmodule MobilizonWeb.ChangesetView do
|
|
@moduledoc """
|
|
View for changesets in case of errors
|
|
"""
|
|
use MobilizonWeb, :view
|
|
|
|
@doc """
|
|
Traverses and translates changeset errors.
|
|
|
|
See `Ecto.Changeset.traverse_errors/2` and
|
|
`MobilizonWeb.ErrorHelpers.translate_error/1` for more details.
|
|
"""
|
|
def translate_errors(changeset) do
|
|
Ecto.Changeset.traverse_errors(changeset, &translate_error/1)
|
|
end
|
|
|
|
def render("error.json", %{changeset: changeset}) do
|
|
# When encoded, the changeset returns its errors
|
|
# as a JSON object. So we just pass it forward.
|
|
%{errors: translate_errors(changeset)}
|
|
end
|
|
end
|