diff --git a/src/core/query.ts b/src/core/query.ts index e731472aa0..8feb487a97 100644 --- a/src/core/query.ts +++ b/src/core/query.ts @@ -157,20 +157,6 @@ export class Query { }, this.cacheTime) } - async refetch( - options?: RefetchOptions, - config?: QueryConfig - ): Promise { - try { - return await this.fetch(undefined, config) - } catch (error) { - if (options?.throwOnError === true) { - throw error - } - return undefined - } - } - cancel(): void { this.cancelFetch?.() } @@ -243,7 +229,7 @@ export class Query { ) } - onWindowFocus(): void { + async onWindowFocus(): Promise { if ( this.observers.some( observer => @@ -252,12 +238,17 @@ export class Query { observer.config.refetchOnWindowFocus ) ) { - this.fetch() + try { + await this.fetch() + } catch { + // ignore + } } + this.continue() } - onOnline(): void { + async onOnline(): Promise { if ( this.observers.some( observer => @@ -266,8 +257,13 @@ export class Query { observer.config.refetchOnReconnect ) ) { - this.fetch() + try { + await this.fetch() + } catch { + // ignore + } } + this.continue() } @@ -306,6 +302,35 @@ export class Query { this.scheduleGc() } + async refetch( + options?: RefetchOptions, + config?: QueryConfig + ): Promise { + try { + return await this.fetch(undefined, config) + } catch (error) { + if (options?.throwOnError === true) { + throw error + } + } + } + + async fetchMore( + fetchMoreVariable?: unknown, + options?: FetchMoreOptions, + config?: QueryConfig + ): Promise { + return this.fetch( + { + fetchMore: { + fetchMoreVariable, + previous: options?.previous || false, + }, + }, + config + ) + } + async fetch( options?: FetchOptions, config?: QueryConfig @@ -548,22 +573,6 @@ export class Query { run() }) } - - fetchMore( - fetchMoreVariable?: unknown, - options?: FetchMoreOptions, - config?: QueryConfig - ): Promise { - return this.fetch( - { - fetchMore: { - fetchMoreVariable, - previous: options?.previous || false, - }, - }, - config - ) - } } function getLastPage(pages: TResult[], previous?: boolean): TResult { @@ -578,7 +587,6 @@ function hasMorePages( if (config.infinite && config.getFetchMore && Array.isArray(pages)) { return Boolean(config.getFetchMore(getLastPage(pages, previous), pages)) } - return undefined } function getDefaultState( diff --git a/src/core/queryObserver.ts b/src/core/queryObserver.ts index e8cb6c5f45..f6c4c53057 100644 --- a/src/core/queryObserver.ts +++ b/src/core/queryObserver.ts @@ -122,8 +122,8 @@ export class QueryObserver { async fetch(): Promise { try { return await this.currentQuery.fetch(undefined, this.config) - } catch (error) { - return undefined + } catch { + // ignore } }