I am relying on Ecto to return an error when an insert fails a database level constraint.
Is it possible to run different code depending on the error type returned by Ecto?
case Repo.insert(changeset) do
{:ok, _} ->
IO.puts("inserted")
{:error, message} when is_certain_ecto_error ->
IO.puts("database constraint error")
{:error, message} ->
IO.puts("everything else error")
end
{:error, changeset}
tuple when an insert fails. You will need to look at the errors and decide what to do. - Justin Wood