mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 05:13:33 +12:00
improvement: unwrap forbidden errors, instead of reporting on the whole
This commit is contained in:
parent
5e87c52f9b
commit
839bdcb126
2 changed files with 1 additions and 25 deletions
24
lib/error.ex
24
lib/error.ex
|
@ -110,30 +110,6 @@ defimpl AshGraphql.Error, for: Ash.Error.Query.Required do
|
|||
end
|
||||
end
|
||||
|
||||
defimpl AshGraphql.Error, for: Ash.Error.Forbidden do
|
||||
def to_error(error) do
|
||||
message =
|
||||
if Application.get_env(:ash_graphql, :policies)[:show_policy_breakdowns?] ||
|
||||
false do
|
||||
Enum.map_join(
|
||||
error.errors,
|
||||
"\n\n\n\n\n",
|
||||
fn error -> Ash.Error.Forbidden.Policy.report(error, help_text?: false) end
|
||||
)
|
||||
else
|
||||
"forbidden"
|
||||
end
|
||||
|
||||
%{
|
||||
message: message,
|
||||
short_message: "forbidden",
|
||||
vars: Map.new(error.vars),
|
||||
code: Ash.ErrorKind.code(error),
|
||||
fields: []
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
defimpl AshGraphql.Error, for: Ash.Error.Forbidden.Policy do
|
||||
def to_error(error) do
|
||||
message =
|
||||
|
|
|
@ -1220,7 +1220,7 @@ defmodule AshGraphql.Graphql.Resolver do
|
|||
errors
|
||||
|> List.wrap()
|
||||
|> Enum.flat_map(fn
|
||||
%Ash.Error.Invalid{errors: errors} ->
|
||||
%class{errors: errors} when class in [Ash.Error.Invalid, Ash.Error.Forbidden] ->
|
||||
unwrap_errors(List.wrap(errors))
|
||||
|
||||
errors ->
|
||||
|
|
Loading…
Reference in a new issue