From 5289a9e398f2b2cfd75e2cb1deef2d64d4c056fe Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 4 Aug 2020 12:22:13 -0400 Subject: [PATCH] avoid out of bound errors --- services/gunDB/contact-api/getters/feed.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/gunDB/contact-api/getters/feed.js b/services/gunDB/contact-api/getters/feed.js index 5c8ef112..22e160a7 100644 --- a/services/gunDB/contact-api/getters/feed.js +++ b/services/gunDB/contact-api/getters/feed.js @@ -6,6 +6,8 @@ const isFinite = require('lodash/isFinite') const shuffle = require('lodash/shuffle') const R = require('ramda') +const { asyncFilter } = require('../../../../utils') + const Follows = require('./follows') const Wall = require('./wall') @@ -61,7 +63,13 @@ const getFeedPage = async page => { page ) - const publicKeys = pagedPublicKeys[publicKeyGroupIdx] + const publicKeysRaw = pagedPublicKeys[publicKeyGroupIdx] + const publicKeys = await asyncFilter( + publicKeysRaw, + // reject public keys for which the page to request would result in an out + // of bounds error + async pk => pageToRequest <= (await Wall.getWallTotalPages(pk)) + ) const fetchedPages = await Promise.all( publicKeys.map(pk => Wall.getWallPage(pageToRequest, pk))