Fix posts and rework graphql errors
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
21
lib/graphql/middleware/error_handler.ex
Normal file
21
lib/graphql/middleware/error_handler.ex
Normal file
@@ -0,0 +1,21 @@
|
||||
defmodule Mobilizon.GraphQL.Middleware.ErrorHandler do
|
||||
@moduledoc """
|
||||
Absinthe Error Handler
|
||||
"""
|
||||
alias Mobilizon.GraphQL.Error
|
||||
|
||||
@behaviour Absinthe.Middleware
|
||||
@impl true
|
||||
def call(resolution, _config) do
|
||||
errors =
|
||||
resolution.errors
|
||||
|> Enum.map(&Error.normalize/1)
|
||||
|> List.flatten()
|
||||
|> Enum.map(&to_absinthe_format/1)
|
||||
|
||||
%{resolution | errors: errors}
|
||||
end
|
||||
|
||||
defp to_absinthe_format(%Error{} = error), do: Map.from_struct(error)
|
||||
defp to_absinthe_format(error), do: error
|
||||
end
|
||||
Reference in New Issue
Block a user