Promise rejections and error thrown are shown in failureReason property instead of error property #6271
-
| 
         I am trying out react query for the first time and I found that something is behaving differently than as given in the documentation. React Query Version: 5.0.0 (using with Next.js) I modified my fetcher function little bit to test both Promise rejection and the throwing error scenario. Scenario 1: const result = useQuery({
    queryKey: ['todos', 1],
    queryFn: async () => {
      if (true) {
        throw new Error('Oh no!')
      }
      if (false) {
        return Promise.reject(new Error('Oh no!'))
      }
  
      return []
    },
  });
  console.log(result)Scenario 2: (With promise rejection) const result = useQuery({
    queryKey: ['todos', 1],
    queryFn: async () => {
      if (false) {
        throw new Error('Oh no!')
      }
      if (true) {
        return Promise.reject(new Error('Oh no! with promise rejection'))
      }
  
      return []
    },
  });
  console.log(result)Correct me if I am missing something.  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
| 
         react-query does 3 retries per default.   | 
  
Beta Was this translation helpful? Give feedback.



react-query does 3 retries per default.
failureCountincreases to 3 with the underlyingfailureReasonbefore the query actually goes into error state. if you want instant error state, setretry: false