Skip to content

Commit

Permalink
added additional error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hanneforth committed Jun 15, 2021
1 parent 4e0cbc1 commit 7026e06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions message.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const errorCode = {
12: "Browser is not running!",
13: "Failed to load session!",
14: "The bot is already authenticated!",
15: "An error was thrown without reasoning by instagram."
15: "An error was thrown without reasoning by instagram.",
16: "Username couldn't be extracted!"
};
const errorTemplate = (code) => {
return {
Expand All @@ -36,7 +37,8 @@ const errorMessage = {
"browserNotRunning": errorTemplate(12),
"failedToLoadSession": errorTemplate(13),
"botAlreadyAuthenticated": errorTemplate(14),
"errorWithoutReasoning": errorTemplate(15)
"errorWithoutReasoning": errorTemplate(15),
"usernameNotExtracted": errorTemplate(16)
};

module.exports = { errorMessage };
4 changes: 3 additions & 1 deletion scripts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ const getPostDetails = async (page, identifier) => {

const postId = link.split("/")[4];

const username = await page.evaluate(() => [...document.querySelectorAll(".sqdOP.yWX7d._8A5w5.ZIAjV")][0].innerText);
const linksOnPage = await page.evaluate(() => [...document.querySelectorAll("a")].map(el => el.href));
if(linksOnPage.length == 0) throw new IBError(errorMessage.usernameNotExtracted.code, errorMessage.usernameNotExtracted.username);
const username = linksOnPage[0].split("/")[3];
const user = new User(`https://www.instagram.com/${username}/`, username, null);

const likesStr = await page.evaluate((postId) => {
Expand Down

0 comments on commit 7026e06

Please sign in to comment.