From 971134863d29031bc01b8218c2000416b4060547 Mon Sep 17 00:00:00 2001 From: Shaun Hamilton Date: Wed, 19 Nov 2025 18:30:34 +0200 Subject: [PATCH] fix(client): retry failed rtk queries (#63976) --- client/src/utils/ajax.ts | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/client/src/utils/ajax.ts b/client/src/utils/ajax.ts index f7da3684b35..4f927660305 100644 --- a/client/src/utils/ajax.ts +++ b/client/src/utils/ajax.ts @@ -1,5 +1,5 @@ import cookies from 'browser-cookies'; -import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; +import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react'; import envData from '../../config/env.json'; import type { @@ -453,13 +453,18 @@ export type GetExamsResponse = Array<{ export const examAttempts = createApi({ reducerPath: 'exam-attempts', - baseQuery: fetchBaseQuery({ - baseUrl: apiLocation, - headers: { - 'CSRF-Token': getCSRFToken() - }, - credentials: 'include' - }), + baseQuery: retry( + fetchBaseQuery({ + baseUrl: apiLocation, + prepareHeaders(headers) { + headers.set('CSRF-Token', getCSRFToken()); + return headers; + }, + credentials: 'include' + }), + // Retry in the case this is the initial request - csrf is not set yet, and initial returns 403 + { maxRetries: 2 } + ), endpoints: build => ({ getExamAttemptsByExamId: build.mutation({ query: examId => `/user/exam-environment/exams/${examId}/attempts` @@ -476,13 +481,18 @@ export const examAttempts = createApi({ export const examEnvironmentAuthorizationTokenApi = createApi({ reducerPath: 'exam-environment-authorization-token', - baseQuery: fetchBaseQuery({ - baseUrl: apiLocation, - headers: { - 'CSRF-Token': getCSRFToken() - }, - credentials: 'include' - }), + baseQuery: retry( + fetchBaseQuery({ + baseUrl: apiLocation, + prepareHeaders(headers) { + headers.set('CSRF-Token', getCSRFToken()); + return headers; + }, + credentials: 'include' + }), + // Retry in the case this is the initial request - csrf is not set yet, and initial returns 403 + { maxRetries: 2 } + ), endpoints: build => ({ postGenerateExamEnvironmentAuthorizationToken: build.mutation< ExamTokenResponse,