Add ENDPOINT_OVERRIDEN error symbol

Show proper 404 page for /u/privacy, /u/accounts, etc
This commit is contained in:
Cadence Fish 2020-02-06 01:32:51 +13:00
parent f8f670c4a9
commit 3b1c6a2849
No known key found for this signature in database
GPG Key ID: 81015DF9AA8607E1
4 changed files with 6 additions and 4 deletions

View File

@ -41,6 +41,7 @@ async function fetchUser(username, isRSS) {
function fetchUserFromHTML(username) { function fetchUserFromHTML(username) {
return userRequestCache.getOrFetch("user/"+username, false, true, () => { return userRequestCache.getOrFetch("user/"+username, false, true, () => {
return switcher.request("user_html", `https://www.instagram.com/${username}/`, async res => { return switcher.request("user_html", `https://www.instagram.com/${username}/`, async res => {
if (res.status === 301) throw constants.symbols.ENDPOINT_OVERRIDDEN
if (res.status === 302) throw constants.symbols.INSTAGRAM_DEMANDS_LOGIN if (res.status === 302) throw constants.symbols.INSTAGRAM_DEMANDS_LOGIN
if (res.status === 429) throw constants.symbols.RATE_LIMITED if (res.status === 429) throw constants.symbols.RATE_LIMITED
return res return res

View File

@ -62,7 +62,8 @@ let constants = {
NOT_FOUND: Symbol("NOT_FOUND"), NOT_FOUND: Symbol("NOT_FOUND"),
NO_SHARED_DATA: Symbol("NO_SHARED_DATA"), NO_SHARED_DATA: Symbol("NO_SHARED_DATA"),
INSTAGRAM_DEMANDS_LOGIN: Symbol("INSTAGRAM_DEMANDS_LOGIN"), INSTAGRAM_DEMANDS_LOGIN: Symbol("INSTAGRAM_DEMANDS_LOGIN"),
RATE_LIMITED: Symbol("RATE_LIMITED") RATE_LIMITED: Symbol("RATE_LIMITED"),
ENDPOINT_OVERRIDDEN: Symbol("ENDPOINT_OVERRIDDEN")
}, },
database_version: 1 database_version: 1

View File

@ -15,7 +15,7 @@ module.exports = [
content: xml content: xml
} }
}).catch(error => { }).catch(error => {
if (error === constants.symbols.NOT_FOUND) { if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
return render(404, "pug/friendlyerror.pug", { return render(404, "pug/friendlyerror.pug", {
statusCode: 404, statusCode: 404,
title: "Not found", title: "Not found",

View File

@ -60,7 +60,7 @@ module.exports = [
} }
return render(200, "pug/user.pug", {url, user, constants}) return render(200, "pug/user.pug", {url, user, constants})
}).catch(error => { }).catch(error => {
if (error === constants.symbols.NOT_FOUND) { if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
return render(404, "pug/friendlyerror.pug", { return render(404, "pug/friendlyerror.pug", {
statusCode: 404, statusCode: 404,
title: "Not found", title: "Not found",
@ -100,7 +100,7 @@ module.exports = [
} }
} }
}).catch(error => { }).catch(error => {
if (error === constants.symbols.NOT_FOUND) { if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
return render(404, "pug/friendlyerror.pug", { return render(404, "pug/friendlyerror.pug", {
statusCode: 404, statusCode: 404,
title: "Not found", title: "Not found",