Created
April 28, 2019 12:54
-
-
Save sultaniman/a2b2e89e45d363a4111c3b014978bc5e to your computer and use it in GitHub Desktop.
Absinthe resolver action wrapper
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
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