Skip to content

Commit b799bfa

Browse files
committed
* skip dehydrate for queries with FetchError whose .statusCode is 401 and retry them while hydrating @ vue-query.config.ts
* disable the default `retry: 1` and set one second timeout in `ofetch` options @ `api/index.ts` @ fe
1 parent 3d641b3 commit b799bfa

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

fe/src/api/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export const queryFunction = async <TResponse>
5151
Accept: 'application/json',
5252
...requestHeaders
5353
},
54-
signal
54+
signal,
55+
retry: 0,
56+
timeout: 1000
5557
}
5658
) as TResponse;
5759
} catch (e: unknown) {

fe/vue-query.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
export default defineVueQueryPluginHook(() => {
1+
import type { PluginHookReturn } from '@n0099/vue-query-nuxt/dist/runtime/types.js';
2+
import { FetchError } from 'ofetch';
3+
4+
export default defineVueQueryPluginHook((): PluginHookReturn => {
25
return {
36
dehydrateOptions: { // https://github.com/Hebilicious/vue-query-nuxt/issues/108#issuecomment-2908075286
4-
shouldDehydrateQuery: () => true
7+
shouldDehydrateQuery: query =>
8+
!(query.state.status === 'error' && query.state.error instanceof FetchError && query.state.error.statusCode === 401)
59
}
610
};
711
});

0 commit comments

Comments
 (0)