improvement: add key to InvalidKeyset error

This commit is contained in:
Zach Daniel 2022-05-30 16:41:49 -04:00
parent c4de4383e0
commit 067228980e
2 changed files with 6 additions and 6 deletions

View file

@ -2,15 +2,15 @@ defmodule Ash.Error.Page.InvalidKeyset do
@moduledoc "Used when a value is provided for a keyset that cannot be Base64 decoded."
use Ash.Error.Exception
def_ash_error([:value], class: :invalid)
def_ash_error([:value, :key], class: :invalid)
defimpl Ash.ErrorKind do
def id(_), do: Ash.UUID.generate()
def code(_), do: "invalid_keyset"
def message(%{value: value}) do
"Invalid value provided as a keyset: #{inspect(value)}"
def message(%{value: value, key: key}) do
"Invalid value provided as a keyset for #{to_string(key)}: #{inspect(value)}"
end
end
end

View file

@ -58,7 +58,7 @@ defmodule Ash.Page.Keyset do
|> Keyword.keys()
|> Enum.sort()
with {:ok, decoded} <- decode_values(values),
with {:ok, decoded} <- decode_values(values, after_or_before),
{:ok, zipped} <- zip_fields(sort_fields, decoded) do
field_values =
Enum.map(sort, fn {field, direction} ->
@ -85,7 +85,7 @@ defmodule Ash.Page.Keyset do
end)
end
defp decode_values(values) do
defp decode_values(values, key) do
{:ok,
values
|> URI.decode_www_form()
@ -93,7 +93,7 @@ defmodule Ash.Page.Keyset do
|> non_executable_binary_to_term([:safe])}
rescue
_e ->
{:error, Ash.Error.Page.InvalidKeyset.exception(value: values)}
{:error, Ash.Error.Page.InvalidKeyset.exception(value: values, key: key)}
end
defp filters(keyset, after_or_before) do