handle try_until failures

This commit is contained in:
Daniel Lugo 2020-08-04 12:47:19 -04:00
parent 48894b27c4
commit 1d32d636c2

View file

@ -2078,7 +2078,9 @@ module.exports = async (
return res.status(200).json({ return res.status(200).json({
posts: await GunGetters.getFeedPage(page) posts: await GunGetters.getFeedPage(page)
}) })
} else if (try_until) { }
if (try_until) {
const pages = range(1, MAX_PAGES_TO_FETCH_FOR_TRY_UNTIL) const pages = range(1, MAX_PAGES_TO_FETCH_FOR_TRY_UNTIL)
const promises = pages.map(p => GunGetters.getFeedPage(p)) const promises = pages.map(p => GunGetters.getFeedPage(p))
@ -2090,7 +2092,6 @@ module.exports = async (
if (idxIfFound > -1) { if (idxIfFound > -1) {
results = results.slice(0, idxIfFound + 1) results = results.slice(0, idxIfFound + 1)
}
const posts = flatten(results) const posts = flatten(results)
@ -2099,6 +2100,15 @@ module.exports = async (
}) })
} }
// we couldn't find the posts leading up to the requested post
// (try_until) Let's just return the ones we found with together with a
// 205 code (client should refresh UI)
return res.status(205).json({
posts: results[0] || []
})
}
return res.status(400).json({ return res.status(400).json({
errorMessage: `Must provide at least a page or a try_until query param.` errorMessage: `Must provide at least a page or a try_until query param.`
}) })