mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(client): retry failed rtk queries (#63976)
This commit is contained in:
+25
-15
@@ -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<Attempt[], string>({
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user