diff --git a/packages/datagateway-common/src/api/retryICATErrors.ts b/packages/datagateway-common/src/api/retryICATErrors.ts index 26056ddd3..bb879acbd 100644 --- a/packages/datagateway-common/src/api/retryICATErrors.ts +++ b/packages/datagateway-common/src/api/retryICATErrors.ts @@ -1,7 +1,7 @@ import { AxiosError } from 'axios'; import { useQueryClient } from 'react-query'; -export const createRetryICATErrors = ( +const createRetryICATErrors = ( retries: number ): ((failureCount: number, error: AxiosError) => boolean) => { return (failureCount: number, error: AxiosError) => @@ -26,7 +26,7 @@ const baseRetryICATErrors = ( return true; }; -const useRetryICATErrors = (): (( +export const useRetryICATErrors = (): (( failureCount: number, error: AxiosError ) => boolean) => { @@ -34,9 +34,12 @@ const useRetryICATErrors = (): (( const opts = queryClient.getDefaultOptions(); // TODO: do we want to be more elegant in handling other types of retry... const retries = - typeof opts.queries?.retry === 'number' ? opts.queries.retry : 3; + typeof opts.queries?.retry === 'number' + ? opts.queries.retry + : // explicitly handle boolean case as we set this in tests + opts.queries?.retry === false + ? 0 + : 3; return createRetryICATErrors(retries); }; - -export { useRetryICATErrors }; diff --git a/packages/datagateway-common/src/setupTests.tsx b/packages/datagateway-common/src/setupTests.tsx index 8ae41eb75..c4f3b73b8 100644 --- a/packages/datagateway-common/src/setupTests.tsx +++ b/packages/datagateway-common/src/setupTests.tsx @@ -65,7 +65,7 @@ setLogger({ // mock retry function to ensure it doesn't slow down query failure tests jest.mock('./api/retryICATErrors', () => ({ __esModule: true, - default: jest.fn().mockReturnValue(false), + useRetryICATErrors: jest.fn(() => () => false), })); // Mock Date.toLocaleDateString so that it always uses en-GB as locale and UTC timezone diff --git a/packages/datagateway-dataview/src/state/actions/actions.test.tsx b/packages/datagateway-dataview/src/state/actions/actions.test.tsx index de59fbba3..9a9e3d378 100644 --- a/packages/datagateway-dataview/src/state/actions/actions.test.tsx +++ b/packages/datagateway-dataview/src/state/actions/actions.test.tsx @@ -102,7 +102,7 @@ describe('Actions', () => { features: {}, idsUrl: 'ids', apiUrl: 'api', - retries: 1, + queryRetries: 1, breadcrumbs: [ { matchEntity: 'test', diff --git a/packages/datagateway-search/src/state/actions/actions.test.tsx b/packages/datagateway-search/src/state/actions/actions.test.tsx index d40924749..decc3942a 100644 --- a/packages/datagateway-search/src/state/actions/actions.test.tsx +++ b/packages/datagateway-search/src/state/actions/actions.test.tsx @@ -62,7 +62,7 @@ describe('Actions', () => { apiUrl: 'api', downloadApiUrl: 'download-api', icatUrl: 'icat', - retries: 0, + queryRetries: 0, selectAllSetting: false, searchableEntities: ['investigation', 'dataset', 'datafile'], maxNumResults: 150,