Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom error handeling #138

Closed
monorkin opened this issue Jan 2, 2018 · 4 comments
Closed

Custom error handeling #138

monorkin opened this issue Jan 2, 2018 · 4 comments

Comments

@monorkin
Copy link

monorkin commented Jan 2, 2018

Hi!

I'm experiencing issues while using Absinthe.Plug in conjunction with Sentry (an error logging service). I can't get Sentry to report an error (neither through a Plug nor through :error_logger).

I've managed to find a similar issue on their issue tracker and after some digging figured out that this line causes the same problem as the one outlined in the issue.

My question is, is there a way to implement custom error handling with this library? Or o way to get the described integration to work?

@benwilson512
Copy link
Contributor

I'm a bit unclear on what it is that you're looking for here. Are you trying to get GraphQL errors sent to sentry?

@monorkin
Copy link
Author

monorkin commented Jan 18, 2018

Are you trying to get GraphQL errors sent to sentry?

I am.

@benwilson512
Copy link
Contributor

Arguably your best bet here is to add a custom phase. Absinthe works by having a big list of modules, and then passing a graphql document through functions on each of those modules. Each module does some part of the execution process.

The idea here is that you can just add an additional module to the end of the list that will do whatever sentry stuff you want.

A phase can be added via the pipeline option to the plug invocation:

plug Absinthe.Plug,
  schema: MyApp.Schema,
  pipeline: {__MODULE__, :absinthe_pipeline}

def absinthe_pipeline(config, opts) do
  config
  |> Absinthe.Plug.default_pipeline(opts)
  |> Absinthe.Pipeline.insert_after(Absinthe.Phase.Document.Result, MyApp.SentryErrors)
end

So in absinthe_pipeline/2 we build the default pipeline, and then add in MyApp.SentryErrors after the result is built. Let's see what that would look like:

defmodule MyApp.SentryErrors do
  def run(blueprint, _) do
    errors = blueprint.result.errors
    # do whatever with errors here
    {:ok, blueprint}
  end
end

Hopefully that gets you off to the right start.

@monorkin
Copy link
Author

@benwilson512 Seems like I can solve this problem that way. Thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants