mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
improvement: add key
to InvalidKeyset
error
This commit is contained in:
parent
c4de4383e0
commit
067228980e
2 changed files with 6 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue