always return a number

This commit is contained in:
Daniel Lugo 2020-06-24 09:17:59 -04:00
parent d139a6a052
commit 4a80fe5caf

View file

@ -8,15 +8,18 @@ const Key = require('../key')
/**
* @returns {Promise<number>}
*/
const getWallTotalPages = () =>
/** @type {Promise<number>} */ (Utils.tryAndWait(
const getWallTotalPages = async () => {
const totalPages = await Utils.tryAndWait(
(_, user) =>
user
.get(Key.WALL)
.get(Key.NUM_OF_PAGES)
.then(),
v => typeof v !== 'number'
)) || 0
)
return typeof totalPages === 'number' ? totalPages : 0
}
/**
* Won't fail if given an invalid page, will return an empty set.