Skip to content

Commit

Permalink
Relocate extended timeout to api.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Drabenstott committed Jun 5, 2024
1 parent 54c44b1 commit 79847a5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/service/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 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: 5 * 1000, // 5 second timeout
timeout: 5 * 1000,
withCredentials: true, // allow setting/passing cookies
xsrfCookieName: CSRF_COOKIE_NAME,
xsrfHeaderName: CSRF_HEADER_KEY,
Expand All @@ -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 {
Expand Down

0 comments on commit 79847a5

Please sign in to comment.