ja_resource icon indicating copy to clipboard operation
ja_resource copied to clipboard

Consider handle_x to use Ecto.InvalidChangesetError for errors

Open joshuataylor opened this issue 7 years ago • 1 comments

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

joshuataylor avatar May 30 '17 11:05 joshuataylor

@joshuataylor could you provide more details? I have taken over maintenance of the project. This issue is almost 3 years old, and not sure how to bite into it. Thanks in advance.

psteininger avatar Jan 24 '20 12:01 psteininger