0

I have used the "instagram-private-api" npm package to change the bio of my intagram profile over time. the code is working on my local machine but not on my ubuntu hosting(azure).

Here is the code:

const { IgApiClient } = require("instagram-private-api")
const ig = new IgApiClient()

const USERNAME = "username"
const PASSWORD = "pass"

ig.state.generateDevice(USERNAME)

const main = async () => {
  await ig.simulate.preLoginFlow()
  await ig.account.login(USERNAME, PASSWORD)

  // log out of Instagram when done
  process.nextTick(async () => await ig.simulate.postLoginFlow())

  // change the bio
  await ig.account.setBiography("testing stuff...")
}

main()

Here is the error that comes:

(node:1470) UnhandledPromiseRejectionWarning: IgResponseError: POST /api/v1/accounts/msisdn_header_bootstrap/ - 302 Found; 
    at Request.handleResponseError (/home/mamba/node_modules/instagram-private-api/dist/core/request.js:126:16)
    at Request.send (/home/mamba/node_modules/instagram-private-api/dist/core/request.js:54:28)
(node:1470) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1470) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Please Help me with this problem, TIA!

1 Answers1

0

Here all the async function written in the given program may or may not return a value . Thus in an event of not receiving any response from the async function a .catch(...) block is expected . The lack of the .catch(..) is the reason you are getting the unhandled promise rejection error .

You can use the following :

.catch((error)=>{
//enter you logic here
console.log("unhandled promice rejection occured");
});

You have to add this at the end of the async functions .

Thus in an event of event of failure the .catch(...) will catch the error and you can also add additional logic when such events occur .

You can refer the following article :

Promises in Node.js (stackabuse.com)

Node.js Process unhandledPromiseRejection Event - GeeksforGeeks

javascript - What is an unhandled promise rejection? - Stack Overflow

What is an unhandled promise rejection? | TOMDUFFYTECH.COM

Mohit Ganorkar
  • 1,917
  • 2
  • 6
  • 11