Skip to content

Commit f74980a

Browse files
committed
Better error handling for interval fetching
Fixes TanStack#124
1 parent 9ba9a4a commit f74980a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ function makeQuery(options) {
177177
// Schedule garbage collection
178178
query.cacheTimeout = setTimeout(
179179
() => {
180-
queries.splice(queries.findIndex(d => d === query), 1)
180+
queries.splice(
181+
queries.findIndex(d => d === query),
182+
1
183+
)
181184
globalStateListeners.forEach(d => d())
182185
},
183186
query.state.isCached ? query.config.cacheTime : 0
@@ -438,7 +441,12 @@ export function useQuery(queryKey, queryFn, config = {}) {
438441
if (config.refetchInterval && !query.refetchInterval) {
439442
query.refetchInterval = setInterval(() => {
440443
if (isDocumentVisible() || config.refetchIntervalInBackground) {
441-
query.fetch()
444+
try {
445+
query.fetch()
446+
} catch (err) {
447+
console.error(err)
448+
// Swallow this error, since it is handled elsewhere
449+
}
442450
}
443451
}, config.refetchInterval)
444452

0 commit comments

Comments
 (0)