diff --git a/src/lib/collectors.js b/src/lib/collectors.js index 0f5631b..a2c185d 100644 --- a/src/lib/collectors.js +++ b/src/lib/collectors.js @@ -76,6 +76,7 @@ async function fetchUser(username, isRSS) { function fetchUserFromHTML(username) { return userRequestCache.getOrFetch("user/"+username, false, true, () => { return switcher.request("user_html", `https://www.instagram.com/${username}/`, async res => { + throw constants.symbols.INSTAGRAM_DEMANDS_LOGIN // TEST if (res.status === 301) throw constants.symbols.ENDPOINT_OVERRIDDEN if (res.status === 302) throw constants.symbols.INSTAGRAM_DEMANDS_LOGIN if (res.status === 429) throw constants.symbols.RATE_LIMITED diff --git a/src/lib/structures/Assistant.js b/src/lib/structures/Assistant.js index a61d6fe..4b518b0 100644 --- a/src/lib/structures/Assistant.js +++ b/src/lib/structures/Assistant.js @@ -26,9 +26,14 @@ class Assistant { if (root.status === "ok") { this.lastRequestStatus = constants.symbols.assistant_statuses.OK resolve(root.data.user) - } else { - this.lastRequestStatus = constants.symbols.assistant_statuses.BLOCKED - reject(constants.symbols.assistant_statuses.BLOCKED) + } else { // "fail" + if (root.identifier === "NOT_FOUND") { + this.lastRequestStatus = constants.symbols.assistant_statuses.OK + reject(constants.symbols.NOT_FOUND) + } else { // blocked + this.lastRequestStatus = constants.symbols.assistant_statuses.BLOCKED + reject(constants.symbols.assistant_statuses.BLOCKED) + } } }).catch(error => { // console.error(error) diff --git a/src/lib/structures/AssistantSwitcher.js b/src/lib/structures/AssistantSwitcher.js index 549eb81..13f72fb 100644 --- a/src/lib/structures/AssistantSwitcher.js +++ b/src/lib/structures/AssistantSwitcher.js @@ -25,6 +25,12 @@ class AssistantSwitcher { const user = await assistant.requestUser(username) return resolve(user) } catch (e) { + if (e === constants.symbols.NOT_FOUND) { + const rejection = Promise.reject(e) + rejection.catch(() => {}) // otherwise we get a warning that the rejection was handled asynchronously + collectors.userRequestCache.set(`user/${username}`, false, rejection) + return reject(e) + } // that assistant broke. try the next one. } } diff --git a/src/site/assistant_api/user.js b/src/site/assistant_api/user.js index fef22f2..7ad771c 100644 --- a/src/site/assistant_api/user.js +++ b/src/site/assistant_api/user.js @@ -65,6 +65,14 @@ module.exports = [ message: "Rate limited by Instagram.", identifier: "RATE_LIMITED" }) + } else if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) { + return reply(404, { + status: "fail", + version: "1.0", + generatedAt: Date.now(), + message: "User not found.", + identifier: "NOT_FOUND" + }) } else { throw error }