From 839bdcb1267e35591797c71232fb8d9799142202 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Fri, 27 Jan 2023 17:11:17 -0500 Subject: [PATCH] improvement: unwrap forbidden errors, instead of reporting on the whole --- lib/error.ex | 24 ------------------------ lib/graphql/resolver.ex | 2 +- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/lib/error.ex b/lib/error.ex index fd81379..607b09f 100644 --- a/lib/error.ex +++ b/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 = diff --git a/lib/graphql/resolver.ex b/lib/graphql/resolver.ex index 042fe3c..7f09df7 100644 --- a/lib/graphql/resolver.ex +++ b/lib/graphql/resolver.ex @@ -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 ->