mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-29 03:15:27 +00:00
83f2880dd9
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
21 lines
535 B
Elixir
21 lines
535 B
Elixir
defmodule Mobilizon.GraphQL.Middleware.ErrorHandler do
|
|
@moduledoc """
|
|
Absinthe Error Handler
|
|
"""
|
|
alias Mobilizon.GraphQL.Error
|
|
|
|
@behaviour Absinthe.Middleware
|
|
@impl Absinthe.Middleware
|
|
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
|