UnhandledPromiseRejectionWarning: Unhandled promise rejection/

1.9k Views Asked by At

I use an example from the viber site but I get this error. What could be wrong? Thanks!

https://developers.viber.com/blog/2017/05/24/test-your-bots-locally

(node:11512) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
<node_internals>/internal/process/warning.js:32
(node:11512) [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.
const ngrok = require("./get_public_url");
const ViberBot = require("viber-bot").Bot;

// Creating the bot with access token, name and avatar
const bot = new ViberBot({
  authToken: "token",
  name: "EchoBot",
  avatar: "url",
});

const http = require("http");
const port = process.env.PORT || 8080;
return ngrok.getPublicUrl().then((publicUrl) => {
  console.log('Set the new webhook to"', publicUrl);
  http
    .createServer(bot.middleware())
    .listen(port, () => bot.setWebhook(publicUrl));
});
1

There are 1 best solutions below

0
On

you need to catch the promise rejection in order to be able to understand what's wrong :

return ngrok.getPublicUrl().then((publicUrl) => {
  console.log('Set the new webhook to"', publicUrl);
  http
    .createServer(bot.middleware())
    .listen(port, () => bot.setWebhook(publicUrl));
}).catch(e => console.error(e));