Skip to content

Commit a5ef57f

Browse files
committed
docs(reference/QueryCache): clarify fetchFailureCount availability in onError callback
1 parent 334161f commit a5ef57f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

docs/reference/QueryCache.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ The `QueryCache` is the storage mechanism for TanStack Query. It stores all the
1111
import { QueryCache } from '@tanstack/react-query'
1212

1313
const queryCache = new QueryCache({
14-
onError: (error) => {
15-
console.log(error)
14+
onError: (error, query) => {
15+
// query.state.fetchFailureCount reflects total attempts (initial + retries)
16+
if (query.state.fetchFailureCount > 1) {
17+
console.error(`Failed after retries:`, error)
18+
} else {
19+
console.error(`First attempt failed:`, error)
20+
}
1621
},
1722
onSuccess: (data) => {
1823
console.log(data)
@@ -38,6 +43,7 @@ Its available methods are:
3843
- `onError?: (error: unknown, query: Query) => void`
3944
- Optional
4045
- This function will be called if some query encounters an error.
46+
- `query.state.fetchFailureCount` indicates how many attempts were made (including retries), which can be used to differentiate a first failure from a failure after retries.
4147
- `onSuccess?: (data: unknown, query: Query) => void`
4248
- Optional
4349
- This function will be called if some query is successful.

0 commit comments

Comments
 (0)