mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-23 00:27:30 +00:00
Handle user not found in assistant
This commit is contained in:
parent
b2b84c0663
commit
99213216f7
@ -76,6 +76,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 => {
|
||||||
|
throw constants.symbols.INSTAGRAM_DEMANDS_LOGIN // TEST
|
||||||
if (res.status === 301) throw constants.symbols.ENDPOINT_OVERRIDDEN
|
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
|
||||||
|
@ -26,10 +26,15 @@ class Assistant {
|
|||||||
if (root.status === "ok") {
|
if (root.status === "ok") {
|
||||||
this.lastRequestStatus = constants.symbols.assistant_statuses.OK
|
this.lastRequestStatus = constants.symbols.assistant_statuses.OK
|
||||||
resolve(root.data.user)
|
resolve(root.data.user)
|
||||||
} else {
|
} 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
|
this.lastRequestStatus = constants.symbols.assistant_statuses.BLOCKED
|
||||||
reject(constants.symbols.assistant_statuses.BLOCKED)
|
reject(constants.symbols.assistant_statuses.BLOCKED)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
// console.error(error)
|
// console.error(error)
|
||||||
this.lastRequestStatus = constants.symbols.assistant_statuses.OFFLINE
|
this.lastRequestStatus = constants.symbols.assistant_statuses.OFFLINE
|
||||||
|
@ -25,6 +25,12 @@ class AssistantSwitcher {
|
|||||||
const user = await assistant.requestUser(username)
|
const user = await assistant.requestUser(username)
|
||||||
return resolve(user)
|
return resolve(user)
|
||||||
} catch (e) {
|
} 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.
|
// that assistant broke. try the next one.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,14 @@ module.exports = [
|
|||||||
message: "Rate limited by Instagram.",
|
message: "Rate limited by Instagram.",
|
||||||
identifier: "RATE_LIMITED"
|
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 {
|
} else {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user