mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-03-21 22:42:06 +00:00
Why: * In order to manage a large number of Firezone Sites, Resources, Policies, etc... a REST API is needed as clicking through the UI is too time consuming, as well as prone to error. By providing a REST API Firezone customers will be able to manage things within their Firezone accounts with code.
17 lines
454 B
Elixir
17 lines
454 B
Elixir
defmodule API.ChangesetJSON do
|
|
def error(%{status: status, changeset: changeset}) do
|
|
%{
|
|
error: %{
|
|
reason: Plug.Conn.Status.reason_phrase(status),
|
|
validation_errors: Ecto.Changeset.traverse_errors(changeset, &translate_error/1)
|
|
}
|
|
}
|
|
end
|
|
|
|
defp translate_error({msg, opts}) do
|
|
Enum.reduce(opts, msg, fn {key, value}, acc ->
|
|
String.replace(acc, "%{#{key}}", fn _ -> to_string(value) end)
|
|
end)
|
|
end
|
|
end
|