1 import { getApiError } from '@proton/shared/lib/api/helpers/apiErrorHelper';
2 import type { ShareMapLink } from '@proton/shared/lib/interfaces/drive/link';
4 import retryOnError from '../../../utils/retryOnError';
5 import { PAGE_SIZE, SESSION_EXPIRED_ERROR_CODE } from '../constants';
6 import type { Session } from '../types';
7 import { getDefaultSessionValue } from '../utils';
8 import type { FetchShareMap } from './useFetchShareMap';
10 export const fetchItemsMetadataPage = async (
12 fetchShareMap: FetchShareMap,
13 sessionName?: Session['sessionName'],
16 links: ShareMapLink[];
20 links: ShareMapLink[];
23 fn: async (sessionName: Session['sessionName'], page?: number) => {
24 const lastIndex = page === undefined ? undefined : page * PAGE_SIZE - 1;
25 const { Links, SessionName, More, Total } = await fetchShareMap({
35 sessionName: SessionName,
41 shouldRetryBasedOnError: (error) => {
42 const apiError = getApiError(error);
43 if (apiError.code === SESSION_EXPIRED_ERROR_CODE) {
50 beforeRetryCallback: async () => {
51 return [getDefaultSessionValue()];
54 })(sessionName, page);