mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 21:13:19 +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
|
||||
|
||||
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
|
||||
{:error, Ash.Error.to_ash_error(error, stacktrace)}
|
||||
end
|
||||
|
|
|
@ -18,6 +18,16 @@ defmodule AshPostgres.FilterTest do
|
|||
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
|
||||
setup do
|
||||
on_exit(fn ->
|
||||
|
|
Loading…
Reference in a new issue