question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ApolloClient onError doesn't catch mutation errors anymore

See original GitHub issue

Here is my client configuration using Apollo Boost :

new ApolloClient({
  uri: `${window.location.origin}/api`,
  cache: new InMemoryCache(),
  onError({ graphQLErrors, networkError }) {
    if(graphQLErrors)
      graphQLErrors.forEach(error => notification.error({
        message: 'Error',
        description: error.message
      }))
    if(networkError)
      notification.error({
        message: 'Network Error',
        description: `A network error has occurred. Please check out your connection.`
      })
  },
  request(operation) {
    const currentUser = readStore('currentUser')
    currentUser && operation.setContext({
      headers: { authorization: currentUser.token }
    })
  }
})

Intended outcome: Before the bug, the onError callback used to catch errors just fine.

Actual outcome: Errors are said to remain uncaught and cause apps (using CRA in my case) to crash.

How to reproduce the issue: Try switching to the latest version of apollo-boost and just throw a Graphql error on the server.

Versions React : 16.12.0 Apollo-boost : 0.4.7

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:47
  • Comments:48 (7 by maintainers)

github_iconTop GitHub Comments

39reactions
schester44commented, Jun 4, 2020

Any update on this? I have a pretty large app that relied on this pattern to minimize the amount of try/catch and .catch that was needed. Made for a super clean code base knowing I could rely on apollo-link-error when needed.

Not sure what changed, guess I need to look at my past few commits, but lately all mutation errors throw an unhandled error.

Is this change documented in a change log somewhere?

35reactions
wapgearcommented, Jul 12, 2021

Any updates on this one? I can’t believe this issue still not addressed yet

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling operation errors - Apollo GraphQL Docs
Apollo Client can encounter a variety of errors when executing operations on your GraphQL server. Apollo Client helps you handle these errors according...
Read more >
Error handling - Apollo GraphQL Docs
By default, the error policy treats any GraphQL Errors as network errors and ends the request chain. It doesn't save any data in...
Read more >
Mutations in Apollo Client - Apollo GraphQL Docs
A callback function that's called when your mutation successfully completes with zero errors (or if errorPolicy is ignore and partial data is returned)....
Read more >
Handling Errors with Apollo Client (React) - YouTube
In this video I talk about handling errors when running queries and mutations using Apollo Client in a React project.Table of contents:00:00 ...
Read more >
GraphQL error handling to the max with Typescript, codegen ...
We'll see in this article how to: achieve a better error representation than the default offered by GraphQL; get type safety using Typescript ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found