Skip to content

Commit

Permalink
Make extended timeout specific to /batch/{pk}/ GET requests
Browse files Browse the repository at this point in the history
And set default timeout back to previous value
  • Loading branch information
Rebecca Drabenstott committed May 20, 2024
1 parent a57c129 commit 38b23fb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/service/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CSRF_COOKIE_NAME, CSRF_HEADER_KEY } from '../constants/authConstants';

const Axios = axios.create({
baseURL: `/petition/api/`,
timeout: 20 * 1000,
timeout: 5 * 1000, // 5 second timeout
withCredentials: true, // allow setting/passing cookies
xsrfCookieName: CSRF_COOKIE_NAME,
xsrfHeaderName: CSRF_HEADER_KEY,
Expand All @@ -20,7 +20,12 @@ export const axiosBaseQuery =
throw new Error('Must provide api instance');
}
const requestConfig = { url, method, data, params, responseType };
if (timeout) {

// 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) {
requestConfig.timeout = timeout;
}
try {
Expand Down

0 comments on commit 38b23fb

Please sign in to comment.