Skip to content

Consider handle_x to use Ecto.InvalidChangesetError for errors #61

@joshuataylor

Description

@joshuataylor

So when a changeset is invalid, Ecto returns an Ecto.InvalidChangesetError. This is what should be used instead of @type validation_errors :: {:error, Ecto.Changeset.t}, as otherwise you have to do changeset.changeset, like as follows:

  def handle_create(_conn, attributes) do
    try do
      post = Post.create(attributes)
      {:ok, post} = post
    rescue
      changeset in [Ecto.InvalidChangesetError] -> {:error, changeset.changeset}
    end
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions