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 21, 2021
1 parent 479f388 commit 5742ec0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions message.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const errorCode = {
18: "Failed to open message channel! This can be caused by you not following the user!",
19: "Failed to click on 'Send' button!",
20: "Failed to send message!",
21: "Failed to type message!"
21: "Failed to type message!",
22: "Failed to login because Instagram detected unusual login attempts on your account. Please check your inbox to verify your login attempt!"
};
const errorTemplate = (code) => {
return {
Expand Down Expand Up @@ -48,7 +49,8 @@ const errorMessage = {
"failedToOpenMessageChannel": errorTemplate(18),
"failedToClickOnSendButton": errorTemplate(19),
"failedToSendMessage": errorTemplate(20),
"failedToTypeMessage": errorTemplate(21)
"failedToTypeMessage": errorTemplate(21),
"unusualLoginAttempt": errorTemplate(22)
};

module.exports = { errorMessage };
2 changes: 2 additions & 0 deletions scripts/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ const login = async (page, username, password) => {
return prev;
}, false));
const accountDoesntExist = await page.evaluate(() => [...document.querySelectorAll("p")].find(p => p.innerHTML == "The username you entered doesn't belong to an account. Please check your username and try again.") ? true : false);
const unusualLoginAttempt = await page.evaluate(() => [...document.querySelectorAll("h2")].find(h2 => h2.innerText == "We Detected An Unusual Login Attempt") ? true : false);

if(wrongPassword) throw new IBLoginError(errorMessage.incorrectPassword.code, errorMessage.incorrectPassword.message, username);
if(waitUntilLoggingIn) throw new IBLoginError(errorMessage.waitBeforeLogin.code, errorMessage.waitBeforeLogin.message, username);
if(accountDoesntExist ? true : false) throw new IBLoginError(errorMessage.accountNotFound.code, errorMessage.accountNotFound.message, username);
if(unusualLoginAttempt) throw new IBLoginError(errorMessage.unusualLoginAttempt.code, errorMessage.unusualLoginAttempt.message, username);

};

Expand Down

0 comments on commit 5742ec0

Please sign in to comment.