Conditional retry

This commit is contained in:
2024-07-29 23:29:56 +02:00
parent 386472e680
commit f6a10c8133
5 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "react",
"private": true,
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"scripts": {
"dev": "vite",
+3 -2
View File
@@ -1,5 +1,6 @@
import { queryOptions } from '@tanstack/react-query';
import { useApi } from '../api/Api';
import { ERRORS } from '../components/Error/Errors';
export const profileSelfQueryOptions = (Api: ReturnType<typeof useApi>) =>
queryOptions({
@@ -8,12 +9,12 @@ export const profileSelfQueryOptions = (Api: ReturnType<typeof useApi>) =>
user: await Api.user(),
posts: await Api.userPosts(Api.authenticatedUser?.id ?? 0),
}),
retry: false,
retry: (count, error) => ('code' in error && error.code !== ERRORS.UNAUTHORIZED ? count < 3 : false),
});
export const profileQueryOptions = (Api: ReturnType<typeof useApi>, id?: number) =>
queryOptions({
queryKey: ['profile', { id }],
queryFn: async () => ({ user: await Api.user(id), posts: await Api.userPosts(id) }),
retry: false,
retry: (count, error) => ('code' in error && error.code !== ERRORS.UNAUTHORIZED ? count < 3 : false),
});