首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UnhandledPromiseRejectionWarning:未处理的承诺拒绝/

UnhandledPromiseRejectionWarning:未处理的承诺拒绝/
EN

Stack Overflow用户
提问于 2020-09-30 02:16:00
回答 1查看 1.4K关注 0票数 3

我使用了一个来自viber站点的例子,但是我得到了这个错误。会出什么问题呢?谢谢!

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

代码语言:javascript
复制
(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.
代码语言:javascript
复制
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));
});
EN

回答 1

Stack Overflow用户

发布于 2020-09-30 06:10:50

您需要捕获promise rejection,以便能够理解哪里出了问题:

代码语言:javascript
复制
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));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64125354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档