improvement: unwrap forbidden errors, instead of reporting on the whole

This commit is contained in:
Zach Daniel 2023-01-27 17:11:17 -05:00
parent 5e87c52f9b
commit 839bdcb126
2 changed files with 1 additions and 25 deletions

View file

@ -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 =

View file

@ -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 ->