Skip to content

Commit 5e082c5

Browse files
committed
fix: use 404 for Ash.Error.Query.NotFound
fix: properly fall back to `filter` or nothing for built-in not Found
1 parent ebc6d9f commit 5e082c5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/ash_json_api/error/error.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ defimpl AshJsonApi.ToJsonApiError, for: Ash.Error.Query.NotFound do
312312
def to_json_api_error(error) do
313313
%AshJsonApi.Error{
314314
id: Ash.UUID.generate(),
315-
status_code: AshJsonApi.Error.class_to_status(error.class),
315+
status_code: 404,
316316
code: "not_found",
317317
title: "NotFound",
318318
detail: "could not be found",

lib/ash_json_api/error/not_found.ex

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule AshJsonApi.Error.NotFound do
2525
filter = error.filter
2626
resource = error.resource
2727

28-
if is_map(filter) || Keyword.keyword?(filter) do
28+
if is_map(filter) || (Keyword.keyword?(filter) && filter not in [[], []]) do
2929
filter =
3030
Enum.map_join(filter, ", ", fn {key, value} ->
3131
try do
@@ -38,7 +38,11 @@ defmodule AshJsonApi.Error.NotFound do
3838

3939
"No #{AshJsonApi.Resource.Info.type(resource)} record found with `#{filter}`"
4040
else
41-
"No #{AshJsonApi.Resource.Info.type(resource)} record found with `#{inspect(filter)}`"
41+
if is_nil(error.filter) do
42+
"No #{AshJsonApi.Resource.Info.type(resource)} record found"
43+
else
44+
"No #{AshJsonApi.Resource.Info.type(resource)} record found with `#{inspect(filter)}`"
45+
end
4246
end
4347
end
4448
end

0 commit comments

Comments
 (0)