Skip to content

Instantly share code, notes, and snippets.

@sultaniman
Created April 28, 2019 12:54
Show Gist options
  • Select an option

  • Save sultaniman/a2b2e89e45d363a4111c3b014978bc5e to your computer and use it in GitHub Desktop.

Select an option

Save sultaniman/a2b2e89e45d363a4111c3b014978bc5e to your computer and use it in GitHub Desktop.

Revisions

  1. sultaniman created this gist Apr 28, 2019.
    29 changes: 29 additions & 0 deletions absinthe-resolver-action-wrapper.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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