Merge pull request #108 from shocknet/fix/wall-page-zero
forbid page zero for wall
This commit is contained in:
commit
ebf6704d66
2 changed files with 11 additions and 5 deletions
|
|
@ -38,11 +38,10 @@ const getWallTotalPages = async publicKey => {
|
||||||
const getWallPage = async (page, publicKey) => {
|
const getWallPage = async (page, publicKey) => {
|
||||||
const totalPages = await getWallTotalPages(publicKey)
|
const totalPages = await getWallTotalPages(publicKey)
|
||||||
|
|
||||||
if (page === 0 || totalPages === 0) {
|
if (page === 0) {
|
||||||
return {
|
throw new RangeError(
|
||||||
count: 0,
|
`Page number cannot be zero, only positive and negative integers are allowed.`
|
||||||
posts: {}
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const actualPageIdx = page < 0 ? totalPages + page : page - 1
|
const actualPageIdx = page < 0 ? totalPages + page : page - 1
|
||||||
|
|
|
||||||
|
|
@ -1856,6 +1856,13 @@ module.exports = async (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pageNum === 0) {
|
||||||
|
return res.status(400).json({
|
||||||
|
field: 'page',
|
||||||
|
errorMessage: 'Page must be a non-zero integer'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const totalPages = await GunGetters.getWallTotalPages(publicKey)
|
const totalPages = await GunGetters.getWallTotalPages(publicKey)
|
||||||
const fetchedPage = await GunGetters.getWallPage(pageNum, publicKey)
|
const fetchedPage = await GunGetters.getWallPage(pageNum, publicKey)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue