From 79847a5202792cdaa92102729dc44b4eaec87e82 Mon Sep 17 00:00:00 2001 From: Rebecca Drabenstott Date: Wed, 5 Jun 2024 08:56:39 -0400 Subject: [PATCH] Relocate extended timeout to api.js --- src/service/api.js | 2 +- src/service/axios.js | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/service/api.js b/src/service/api.js index 4b26129c..957bebba 100644 --- a/src/service/api.js +++ b/src/service/api.js @@ -90,7 +90,7 @@ export const api = createApi({ }, }), getBatch: builder.query({ - query: ({ id }) => ({ url: `batch/${id}/`, method: 'get' }), + query: ({ id }) => ({ url: `batch/${id}/`, method: 'get', timeout: 30 * 1000 }), providesTags: (result, _err, { id }) => { const tags = [{ type: 'Batch', id }]; // TODO: Add petitions from this result to redux store diff --git a/src/service/axios.js b/src/service/axios.js index 478141e0..81ee4e64 100644 --- a/src/service/axios.js +++ b/src/service/axios.js @@ -4,7 +4,7 @@ import { CSRF_COOKIE_NAME, CSRF_HEADER_KEY } from '../constants/authConstants'; const Axios = axios.create({ baseURL: `/petition/api/`, - timeout: 5 * 1000, // 5 second timeout + timeout: 5 * 1000, withCredentials: true, // allow setting/passing cookies xsrfCookieName: CSRF_COOKIE_NAME, xsrfHeaderName: CSRF_HEADER_KEY, @@ -20,12 +20,7 @@ export const axiosBaseQuery = throw new Error('Must provide api instance'); } const requestConfig = { url, method, data, params, responseType }; - - // Set a different timeout for batch/{pk}/ GET requests because they can take a long time - const isBatchGetRequest = (url, method) => url?.match(/^batch\/\d+\/$/) !== null && method?.toLowerCase() === 'get'; - if (isBatchGetRequest(url, method)) { - requestConfig.timeout = 30 * 1000; // 30 second timeout - } else if (timeout) { + if (timeout) { requestConfig.timeout = timeout; } try {