Skip to content

Commit d737cba

Browse files
committed
improvement: make error clearer for unused route params
1 parent 535c986 commit d737cba

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/ash_json_api/controllers/helpers.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,14 @@ defmodule AshJsonApi.Controllers.Helpers do
623623
# Normal parameter handling
624624
case Enum.find(action.arguments, &(to_string(&1.name) == key)) do
625625
nil ->
626-
case Ash.Resource.Info.public_attribute(resource, key) do
626+
case Ash.Resource.Info.attribute(resource, key) do
627627
nil ->
628628
{:halt,
629629
{:error,
630630
Ash.Error.Invalid.NoSuchInput.exception(
631631
resource: resource,
632632
action: action.name,
633+
input: key,
633634
inputs: []
634635
)}}
635636

lib/ash_json_api/error/error.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,22 @@ end
359359

360360
defimpl AshJsonApi.ToJsonApiError, for: Ash.Error.Invalid.NoSuchInput do
361361
def to_json_api_error(error) do
362+
vars =
363+
if error.input do
364+
error.vars
365+
|> Map.new()
366+
|> Map.put(:input, error.input)
367+
else
368+
Map.new(error.vars)
369+
end
370+
362371
%AshJsonApi.Error{
363372
id: Ash.UUID.generate(),
364373
status_code: 422,
365374
code: "no_such_input",
366375
title: "NoSuchInput",
367376
detail: "no such input",
368-
meta: Map.new(error.vars)
377+
meta: vars
369378
}
370379
end
371380
end

0 commit comments

Comments
 (0)