View Source Authorizir.ErrorHelpers (Authorizir v1.0.1)

Link to this section Summary

Functions

A helper that transforms changeset errors into a map of messages.

A helper that gets errors for a specific changeset field

Link to this section Functions

@spec errors_on(Ecto.Changeset.t()) :: %{optional(atom()) => [String.t()]}

A helper that transforms changeset errors into a map of messages.

assert {:error, changeset} = Accounts.create_user(%{password: "short"}) assert "password is too short" in errors_on(changeset).password assert %{password: ["password is too short"]} = errors_on(changeset)

Link to this function

errors_on(changeset, field)

View Source
@spec errors_on(Ecto.Changeset.t(), atom()) :: [String.t()]

A helper that gets errors for a specific changeset field

Unlike calling errors_on(changeset).my_field, this does not raise a KeyError if the field has no errors; it instead returns an empty list.