ApolloLink onError throwing exceptions

Here’s what I’d like to achieve: I want to cause an error (network or graphQL) to throw an exception to the calling site. I need to do this because my error reporting library does not work inside of a service worker (chrome extension), so I need to bubble it back up and eventually catch the exception. I need to bubble the error contents as well, so that I can report the complete error.

I tried to do something like this:

    onError(({ graphQLErrors, networkError, operation, forward }) => {
      const { response } = operation.getContext()
      console.log(response, graphQLErrors, networkError)

      // How to get this to go back to requester?
      throw { graphQLErrors, networkError }
    })

But the end result is that my call site doesn’t throw, and I get an unhandled error from somewhere else.

Is this possible with Apollo, or maybe I’m fundamentally misunderstanding a best practice?

I think this may be the case :slight_smile: I removed my onError link and it now throws errors by default. So the default behavior works like I want.

1 Like