Fragments have rate limit symbol handler

This commit is contained in:
Cadence Ember 2020-06-24 20:20:43 +12:00
parent 81b2c77b98
commit 20ea14c0d1
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412
1 changed files with 21 additions and 1 deletions

View File

@ -120,12 +120,12 @@ module.exports = [
},
{
route: `/fragment/user/(${constants.external.username_regex})/(\\d+)`, methods: ["GET"], code: async ({req, url, fill}) => {
const settings = getSettings(req)
return fetchUser(fill[0]).then(async user => {
const pageNumber = +fill[1]
const pageIndex = pageNumber - 1
await user.timeline.fetchUpToPage(pageIndex)
if (user.timeline.pages[pageIndex]) {
const settings = getSettings(req)
return render(200, "pug/fragments/timeline_page.pug", {page: user.timeline.pages[pageIndex], pageIndex, user, url, settings})
} else {
return {
@ -142,6 +142,16 @@ module.exports = [
message: "This user doesn't exist.",
withInstancesLink: false
})
} else if (error === constants.symbols.INSTAGRAM_DEMANDS_LOGIN || error === constants.symbols.RATE_LIMITED) {
return render(503, "pug/friendlyerror.pug", {
statusCode: 503,
title: "Timeline loading blocked",
message: "Timeline loading blocked",
explanation:
"Instagram blocked this server for requesting too many timeline pages."
+"\nThis block is not permanent, and will expire soon."
+"\nPlease wait a few minutes before trying again."
})
} else {
throw error
}
@ -171,6 +181,16 @@ module.exports = [
message: "Somehow, you reached a post that doesn't exist.",
withInstancesLink: false
})
} else if (error === constants.symbols.RATE_LIMITED) {
return render(503, "pug/friendlyerror.pug", {
statusCode: 503,
title: "Post loading blocked",
message: "Post loading blocked",
explanation:
"Instagram blocked this server for requesting too much post data."
+"\nThis block is not permanent, and will expire soon."
+"\nPlease wait a few minutes before trying again."
})
} else {
throw error
}