I need to handle and catch ecto exceptions to return my custom exceptions, my current functions is :
def list_books(filters) when is_list(filters) do
try do
Repo.all(from Book, where: ^filters)
rescue
error -> IO.inspect(error)
end
end
and this the result of Inspect :
** (Protocol.UndefinedError) protocol Enumerable not implemented for %Ecto.Query.CastError{message:
"lib/booker/booker.ex:123: value `\"created├®├®\"` in `where` cannot be cast to type {:parameterized,
Ecto.Enum, %{mappings: [created: \"created\", sold: \"sold\", canceled: \"canceled\", failed: \"failed\"],
on_cast: %{\"canceled\" => :canceled, \"created\" => :created, \"failed\" => :failed, \"succeeded\" =>
:succeeded}, on_dump: %{canceled: \"canceled\", created: \"created\"`
This error for example is when I passed an invalid Enum value (not existing in database).
Is there way to get error.name or code for example ? to handle it (instead of inspecting it)
Thanks