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

Apollo Link onError should provide access to stack trace #436

Open
adrian-skybaker opened this issue Apr 30, 2024 · 4 comments
Open

Apollo Link onError should provide access to stack trace #436

adrian-skybaker opened this issue Apr 30, 2024 · 4 comments
Labels
core Feature requests related to core functionality 🔗 apollo-link Feature requests related to Apollo Link behavior

Comments

@adrian-skybaker
Copy link

When handling errors in https://www.apollographql.com/docs/react/api/link/apollo-link-error/, there is no ability to determine the stack trace of the error that includes the original trigger for the query.

This is problematic both when logging errors locally, and reporting helpful errors to tools like Sentry.io, which accept Error objects and present stack traces helpfully.

Raising a new Error object from within an onError handler doesn't work, presumably because of the callback nature of the handler.

The only workaround I've found is to implement a separate link that populates the stack into the context:

new ApolloLink((operation, forward) => {
  operation.setContext({ clientStackTrace: new Error().stack });
  return forward(operation);
});

This is not ideal as it wastefully records the stack for every request, even if no error occurs.

This gap has been raised several times, but I don't believe it's currently captured as a feature request here:

@jerelmiller
Copy link
Member

Hey @adrian-skybaker 👋

Thanks for opening this request! I think it makes sense for us to add support for Error.cause here which I would imagine would help here quite a bit. This is something we've talked about internally a couple times, but this is good signal that we should look at this perhaps sooner than later.

@jerelmiller jerelmiller added 🔗 apollo-link Feature requests related to Apollo Link behavior core Feature requests related to core functionality labels Apr 30, 2024
@durchanek
Copy link

This would be very helpful, I was also confused why Sentry doesn't show correct stack traces for GQL errors.

@eudis-allwhere
Copy link

Same issue here, hard to trace issues at the Sentry.captureExpception if its called once at the onError apolloLink level. Would be useful to see where the original call and its context came from in the stack

@jerelmiller
Copy link
Member

Hey all 👋

As of 3.11, we are now setting the cause property on ApolloError. If you end up upgrading, let me me know how this works for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Feature requests related to core functionality 🔗 apollo-link Feature requests related to Apollo Link behavior
Projects
None yet
Development

No branches or pull requests

4 participants