mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
fix: raise better error on invalid filter values
closes #154 We still want to build something better directly into `Ash.Filter` that determines field types and casts them up front
This commit is contained in:
parent
ce9ca1ced2
commit
a09dae4d26
2 changed files with 19 additions and 0 deletions
|
@ -1313,6 +1313,15 @@ defmodule AshPostgres.DataLayer do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp handle_raised_error(%Ecto.Query.CastError{} = e, stacktrace, context, resource) do
|
||||||
|
handle_raised_error(
|
||||||
|
Ash.Error.Query.InvalidFilterValue.exception(value: e.value, context: context),
|
||||||
|
stacktrace,
|
||||||
|
context,
|
||||||
|
resource
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
defp handle_raised_error(error, stacktrace, _context, _resource) do
|
defp handle_raised_error(error, stacktrace, _context, _resource) do
|
||||||
{:error, Ash.Error.to_ash_error(error, stacktrace)}
|
{:error, Ash.Error.to_ash_error(error, stacktrace)}
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,16 @@ defmodule AshPostgres.FilterTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "invalid uuid" do
|
||||||
|
test "with an invalid uuid, an invalid error is raised" do
|
||||||
|
assert_raise Ash.Error.Invalid, fn ->
|
||||||
|
Post
|
||||||
|
|> Ash.Query.filter(id == "foo")
|
||||||
|
|> Api.read!()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "citext validation" do
|
describe "citext validation" do
|
||||||
setup do
|
setup do
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
|
|
Loading…
Reference in a new issue