mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
fix: Make get and get! consistent with what they raise when no record found (#325)
This commit is contained in:
parent
fd68d212ef
commit
35a19f800d
2 changed files with 10 additions and 1 deletions
|
@ -1075,7 +1075,7 @@ defmodule Ash.Api do
|
|||
end
|
||||
|
||||
defp unwrap_or_raise!({:error, error}, stacktraces?, _) do
|
||||
exception = Ash.Error.to_ash_error(error)
|
||||
exception = Ash.Error.to_error_class(error)
|
||||
|
||||
exception =
|
||||
if stacktraces? do
|
||||
|
|
|
@ -158,6 +158,15 @@ defmodule Ash.Test.Actions.ReadTest do
|
|||
assert ^post = clear_meta(Api.get!(Post, post.id))
|
||||
end
|
||||
|
||||
test "it raises when there is no matching record" do
|
||||
res =
|
||||
assert_raise Ash.Error.Invalid, fn ->
|
||||
Api.get!(Post, Ash.UUID.generate())
|
||||
end
|
||||
|
||||
assert [%Ash.Error.Query.NotFound{}] = res.errors
|
||||
end
|
||||
|
||||
test "raises an error when the first argument is not a module", %{post: post} do
|
||||
res = assert_raise Ash.Error.Invalid.NoSuchResource, fn -> Api.get("bogus", post.id, []) end
|
||||
assert res.message =~ ~r/Ash.Test.Actions.ReadTest.Api.get\/3/
|
||||
|
|
Loading…
Reference in a new issue