mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
improvement: add ForbiddenField
exception
This commit is contained in:
parent
94815605b9
commit
fcc319d965
1 changed files with 18 additions and 0 deletions
18
lib/ash/error/forbidden/forbidden_field.ex
Normal file
18
lib/ash/error/forbidden/forbidden_field.ex
Normal file
|
@ -0,0 +1,18 @@
|
|||
defmodule Ash.Error.Forbidden.ForbiddenField do
|
||||
@moduledoc "Raised in cases where access to a specific field was prevented"
|
||||
|
||||
require Logger
|
||||
use Ash.Error.Exception
|
||||
|
||||
def_ash_error([:resource, :field], class: :forbidden)
|
||||
|
||||
defimpl Ash.ErrorKind do
|
||||
def id(_), do: Ecto.UUID.generate()
|
||||
|
||||
def message(error) do
|
||||
"Forbidden: cannot access #{error.field} on #{inspect(error.resource)}"
|
||||
end
|
||||
|
||||
def code(_), do: "forbidden_field"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue