React-query: useQuery fails to catch errors thrown during refetch

Created on 15 Aug 2020  路  4Comments  路  Source: tannerlinsley/react-query

Describe the bug
Exceptions thrown during the query refetch don't appear to be being caught.

Even in production, the console log is filled with

Uncaught (in promise) Error: fake error: 2
    at index.js:52
    at c (runtime.js:45)
    at Generator._invoke (runtime.js:264)
    at Generator.e.<computed> [as next] (runtime.js:98)
    at r (asyncToGenerator.js:3)
    at a (asyncToGenerator.js:25)
    at asyncToGenerator.js:32
    at new Promise (<anonymous>)
    at asyncToGenerator.js:21
    at react-query.mjs:812

before it crashes.

See https://codesandbox.io/s/charming-elgamal-286p8?file=/src/index.js for an example.

The hook sets the status to error based on the initial state, but it's hard to tell if it's does anything with the subsequent errors due to the other problems caused by them not being caught.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/charming-elgamal-286p8?file=/src/index.js
  2. wait 10s.
  3. See error

Note that in this example, Fake error 1 comes from the initial query, retry is disabled, and Fake Error 2 comes from the first refresh.

Expected behavior
Since the useQuery hook is returning the error status as well as the error object, I expect that that is the all that's required to handle the error.

bug

All 4 comments

Seems to be partially fixed now. The error still exists when you focus the browser and force a refetch that way.

Seems to be partially fixed now. The error still exists when you focus the browser and force a refetch that way.

I think the error on re-focus is actually a new bug, introduced in 2.12.0. If you take the above sandbox and revert it to 2.11.1, the unhandled error on refocus doesn't happen, but it starts happening on 2.12.0.

The latest version should fix the refocus bug as well now.

The latest version should fix the refocus bug as well now.

Ok... I can't reliably reproduce the issue now. @ggascoigne and I have been trying to track down some related issue we're having on the new releases, though. Reverting to 2.11.1 did solve our issue. We'll open a new issue with more details once we figure out what's going on.

Was this page helpful?
0 / 5 - 0 ratings