Unable to handle errors in local state management
See original GitHub issueIntended 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:
- Created 5 years ago
- Reactions:32
- Comments:19 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.