apollo-client: onError link not working for HTTP multipart subscriptions

onError link is not invoked when an error occurs during an HTTP multipart subscription. It successfully checks the error response from the ‘query’ operation but fails to do the same for the ‘subscription’ operation.

Subscription Response:

{
  "payload": null,
  "errors": [
    {
      "message": "cannot read message from websocket",
      "extensions": { "code": "WEBSOCKET_MESSAGE_ERROR" }
    }
  ]
}

Client:

const errorLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors) {
    graphQLErrors.forEach(({ message, locations, path }) =>
      console.log(
        `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
      )
    );
  }
  if (networkError) console.error(`[Network error]: ${networkError}`);
});

return new ApolloClient<any>({
  link: from([errorLink, httpLink]),
  cache: new InMemoryCache()
});

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

@ssmilin this change was just released in 3.12.9. Please upgrade to that version and you will be able to use RetryLink to handle protocol errors. Thanks!

Great to hear! I will get this PR ready for review with the goal to get this released Monday or Tuesday next week. Thanks for the feedback!

Hey @ssmilin 👋

I’ve opened #12318 to allow RetryLink to work with protocol errors in multipart subscriptions. Can you try out the PR build and see if this works on your end as expected?

npm i https://pkg.pr.new/@apollo/client@12318

Hey @ssmilin 👋

This was just released in 3.12.7. Please upgrade to that version and you should be good to go. Let us know if you have any problems working with it. Thanks!

Hey @ssmilin 👋

@phryneas and I talked about this and we think that making these errors available in onError as protocolErrors makes sense. The symbol added for these protocol errors was done to avoid naming collisions any user-defined fields in extensions.

I can’t guarantee a time-frame on the fix but we’ll try to get to it when we can. Thanks for raising the issue!