Last active
May 7, 2019 21:31
-
-
Save sultaniman/4dbf6f9da6fa1a2800a7a7030647b831 to your computer and use it in GitHub Desktop.
Absinthe middleware handle to handle errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Idp.Middlewares.HandleAPIErrors do | |
@behaviour Absinthe.Middleware | |
alias Idp.EctoHelpers | |
def call(resolution, _config) do | |
errors = | |
resolution | |
|> Map.get(:errors) | |
|> Enum.flat_map(&process_errors/1) | |
%{resolution | errors: errors} | |
end | |
defp process_errors(%Ecto.Changeset{} = changeset) do | |
EctoHelpers.process_errors(changeset) | |
end | |
defp process_errors(error), do: [error] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment