Skip to content

useQuery fails to catch errors thrown during refetchΒ #873

@ggascoigne

Description

@ggascoigne

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions