Skip to content

Instantly share code, notes, and snippets.

@sultaniman
Created April 28, 2019 12:54
Show Gist options
  • Save sultaniman/a2b2e89e45d363a4111c3b014978bc5e to your computer and use it in GitHub Desktop.
Save sultaniman/a2b2e89e45d363a4111c3b014978bc5e to your computer and use it in GitHub Desktop.
Absinthe resolver action wrapper
def action_wrapped(fun) do
case fun.() do
{:ok, result} ->
{:ok, result}
{:error, changeset = %Changeset{}} ->
{
:error,
%{
message: "Changeset errors occurred",
code: :schema_errors,
errors: to_api_errors(changeset)
}
}
# Case for our standard errors in `IdpWeb.Schema.Errors`
{:error, %{code: _}} = error ->
error
{:error, _} ->
{
:error,
%{
message: "Oops! Unknown error",
code: :oops
}
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment