I am trying to make multiple API calls and every call return array with 1000 elements, every element is kind of huge. I need to return ~ 7000 elements (100MB) with 7 API calls, but my code always stoped without any error on 4000 elements. Is it because I am reaching memory limit? How can I be sure ?
My code:
export const getAllFindings = async (assets: [], status: string, assetType: string) => {
let offset = 0;
return await fetch({}, offset);
async function fetch(all, start) {
const newData = await getFindingByAssetIdAndAssetType(assets, status, assetType, offset.toString());
all = {...all, ...newData['collection']};
return (newData.page.currentPage < newData.page.totalPages) ? await fetch(all, offset += limit.FINDINGS) : all;
}
}
/**
* Get findings by asset id and asset type
*
* @param assets
* @param status
* @param assetType
* @param offset
*/
export const getFindingByAssetIdAndAssetType = async (assets: [], status: string, assetType: string, offset: string) => {
const ids = assets.map(({value}) => value);
const apiKey = await storage.get("api_key");
try {
const response = await fetch(await baseURL() + sentinelAPI.FINDINGS +
"?asset_type=" + assetType +
"&status=" + status +
"&asset.id=" + ids +
"&fields=descAndSolution&limit=" + limit.FINDINGS +
"&offset=" + offset,
{
method: 'GET',
headers: {
key: apiKey
},
timeout: 10000
});
if (response.status === statusCode.SUCCESS) {
await logger("Got all findings from Sentinel", logMessageType.INFO);
} else {
await logger("Could not get all SAST findings from Sentinel. Response: " + await response.json(), logMessageType.WARNING);
}
return response.json();
} catch (err) {
await logger("getSASTFindingByAssetId()" + err.message.toString(), logMessageType.ERROR);
}
}