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.

Unable to handle errors in local state management

See original GitHub issue

Intended outcome:

The following @client only query:

const GET_COUNT = gql`
  query GetCount {
    count @client
  }
`;

<Query query={GET_COUNT}>
  {({ loading, error, data }) => {
    if (loading) {
      return <p>Loading GET_COUNT query</p>;
    }
    if (error) {
      return <p>An error ocurred: {error.message}</p>;
    }
    return <p>Page ready</p>
  }}
</Query>

Should be capable of handling an error returned by the resolver:

const resolvers = {
  Query: {
    count() {
      throw new Error('Oh no!')
    }
  }
};

Actual outcome:

The query renders again with error set with the thrown error, but it renders again immediately after with error as undefined, so It’s not possible to actually handle the error.

How to reproduce the issue:

I created a repo showing the error, which also shows a error with apollo dev tools: https://github.com/lfades/apollo-state-issue. It’s important to notice that I’m not using a GraphQL backend and just using local state management.

Versions

Check the versions in the repo 🙏

Thank you.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:32
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
ryaninventscommented, Oct 14, 2019

I’m encountering the same issue. If I understand correctly, the fix would be to add a catch to this promise continuation. Let me know if a PR would be welcome on this; I’d be happy to contribute.

If there were a documented method for writing errors directly to the cache, that could be a feasible short-term workaround.

10reactions
boennemanncommented, Jul 23, 2019

Hey all,

For any production application missing error handling is a total blocker. With the present behavior it’s impossible to use local state management at all.

Is there any update, or a work around for this? Or maybe a pointer on where one would start working on a fix?

Thanks, Stephan

Edit: For anyone else coming here: Moving back to https://github.com/apollographql/apollo-link-state works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling operation errors - Apollo GraphQL Docs
These are errors related to the server-side execution of a GraphQL operation. They include: Syntax errors (e.g., a query was malformed); Validation errors...
Read more >
Correct way of error handling in React-Redux - Stack Overflow
Usually the best approach to error handling with redux is to have an error field in state that is then passed to an...
Read more >
React Query Error Handling | TkDodo's blog
Handling errors is an integral part of working with asynchronous data, especially data fetching. We have to face it: Not all requests will...
Read more >
Centralizing API error handling in React apps - ITNEXT
... handling your API errors once and for all in a centralized and easily extendable way, regardless of the state-management library (Redux, ...
Read more >
Error Handling in React 16 – React Blog
In the past, JavaScript errors inside components used to corrupt React's internal state and cause it to emit cryptic errors on next renders....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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