Skip to content

Commit 91ee21a

Browse files
authored
Merge pull request #349 from artiom/fix/handle-invalid-query-different-formats
fix: handle invalid query error different formats
2 parents faec814 + 0de4734 commit 91ee21a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/ash_phoenix/form_data/error.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ end
1414

1515
defimpl AshPhoenix.FormData.Error, for: Ash.Error.Query.InvalidQuery do
1616
def to_form_error(error) do
17-
{error.field, error.message, error.vars}
17+
fields = List.wrap(error.field || Map.get(error, :fields) || [])
18+
19+
for field <- fields do
20+
{field, error.message, error.vars}
21+
end
1822
end
1923
end
2024

test/form_data_helpers_test.exs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
defmodule AshPhoenix.FormDataHelpersTest do
2+
use ExUnit.Case
3+
4+
alias AshPhoenix.FormData.Helpers
5+
6+
describe "transform_errors" do
7+
test "when InvalidQuery error is using field" do
8+
form = AshPhoenix.Test.User.form_to_create()
9+
message = "invalid email"
10+
11+
errors =
12+
Helpers.transform_errors(
13+
form,
14+
[
15+
Ash.Error.Query.InvalidQuery.exception(
16+
field: :email,
17+
message: message,
18+
path: [:email]
19+
)
20+
],
21+
[:email]
22+
)
23+
24+
assert [email: {message, []}] == errors
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)