Skip to content

Commit 41abfc1

Browse files
geroplAlexTugarev
andauthored
[dashboard] retry useUserQuery if error code is not 401 – WEB-560 (#18033)
* [dashboard] retry useUserQuery if error code is not 401 * [dashboard] Add doRetryUserLoader feature flag --------- Co-authored-by: Alex Tugarev <[email protected]>
1 parent ce63317 commit 41abfc1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

components/dashboard/src/data/featureflag-query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const featureFlags = {
2424
enableDedicatedOnboardingFlow: false,
2525
usageDownload: false,
2626
phoneVerificationByCall: false,
27+
doRetryUserLoader: true,
2728
};
2829

2930
export const useFeatureFlag = (featureFlag: keyof typeof featureFlags) => {

components/dashboard/src/hooks/use-user-loader.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import { trackLocation } from "../Analytics";
1111
import { refreshSearchData } from "../components/RepositoryFinder";
1212
import { useQuery } from "@tanstack/react-query";
1313
import { noPersistence } from "../data/setup";
14+
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
15+
import { useFeatureFlag } from "../data/featureflag-query";
1416

1517
export const useUserLoader = () => {
1618
const { user, setUser } = useContext(UserContext);
19+
const doRetryUserLoader = useFeatureFlag("doRetryUserLoader");
1720

1821
// For now, we're using the user context to store the user, but letting react-query handle the loading
1922
// In the future, we should remove the user context and use react-query to access the user
@@ -27,8 +30,15 @@ export const useUserLoader = () => {
2730
// We'll let an ErrorBoundary catch the error
2831
useErrorBoundary: true,
2932
// It's important we don't retry as we want to show the login screen as quickly as possible if a 401
30-
// TODO: In the future we can consider retrying for non 401 errors
31-
retry: false,
33+
retry: (_failureCount: number, error: Error & { code?: number }) => {
34+
if (!doRetryUserLoader) {
35+
return false;
36+
}
37+
return error.code !== ErrorCodes.NOT_AUTHENTICATED;
38+
},
39+
// docs: https://tanstack.com/query/v4/docs/react/guides/query-retries
40+
// backoff by doubling, max. 10s
41+
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000),
3242
cacheTime: 1000 * 60 * 60 * 1, // 1 hour
3343
staleTime: 1000 * 60 * 60 * 1, // 1 hour
3444
onSuccess: (loadedUser) => {

0 commit comments

Comments
 (0)