Skip to content

Smart query retry: skip 4xx, retry 5xx/network errors #2024

Description

@brian-smith-tcril

The app query client (src/queryClient.ts) sets no retry option, so React Query's default applies — 3 retries with exponential backoff for every error, including 4xx. Expected client errors then retry pointlessly: e.g. the courseware outline's expected 403 (denied/logged-out learner) retries 3× (~7s) before it finally settles, and any 4xx slow-fails behind the backoff.

Adopt a smart retry that fails fast on 4xx and only retries server/network errors — the same policy landed in openedx/frontend-app-learner-dashboard#801. Use the existing getResponseStatus helper (src/data/http-error.ts) for consistency with the onError logging.

Proposed change (drafted by Claude 🤖)
export const createQueryClient = (store: Store) => new QueryClient({
  queryCache: createAppQueryCache(store),
  defaultOptions: {
    queries: {
      retry: (failureCount, error) => {
        const status = getResponseStatus(error);
        if (status !== undefined && status >= 400 && status < 500) { return false; }
        return failureCount < 3;
      },
    },
  },
});

Test: a 4xx query calls the fn once (no retry); a 5xx/network query retries up to 3×.

Part of #1946.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions