首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NestJS - UnhandledPromiseRejectionWarning

NestJS - UnhandledPromiseRejectionWarning
EN

Stack Overflow用户
提问于 2021-05-18 10:57:33
回答 3查看 2.3K关注 0票数 1

短版本:,我正在寻找一种使用nodeJS提供的“--跟踪警告”标志来运行我的NestJS应用程序的方法。有什么方法可以做到这一点吗?还是NestJS提供了类似的功能?

长版本:

嗨!这里是NestJS noob。我正在尝试运行我正在开发的NestJS应用程序的开发版本。但是,在启动应用程序时,我会看到下面的错误。

很明显,它在某个地方遗漏了一个追赶错误!然而,开发版本有很多更新,这个错误可以出现在任何地方,所以我希望有一种更有效的方法来发现这个错误,而不仅仅是检查每个新函数!在错误消息中,有一些关于启动应用程序(node --trace-warnings ...)时要运行的标志的提示。但是,这些是针对节点而不是NestJS的。

因此,我的问题是,有什么方法可以使用--跟踪警告标志来运行NestJS,还是有其他有效的方法来找出我遗漏了什么地方的追赶错误?

提前感谢!

错误:

代码语言:javascript
运行
复制
    (node:72899) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:72899) 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:72899) [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.
(node:72899) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:72899) 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: 2)
EN

回答 3

Stack Overflow用户

发布于 2021-05-24 21:42:50

嗯,6379是Redis的默认端口,似乎Nest无法连接到它:)

顺便说一句,看看这段话:https://docs.nestjs.com/exception-filters#catch-everything

为了捕获每个未处理的异常(不管异常类型如何),将@

()装饰器的参数列表保留为空,例如@ catch ()。

代码语言:javascript
运行
复制
import {
  ExceptionFilter,
  Catch,
  ArgumentsHost,
  HttpException,
  HttpStatus,
} from '@nestjs/common';

@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
  catch(exception: unknown, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse();
    const request = ctx.getRequest();

    const status =
      exception instanceof HttpException
        ? exception.getStatus()
        : HttpStatus.INTERNAL_SERVER_ERROR;

    response.status(status).json({
      statusCode: status,
      timestamp: new Date().toISOString(),
      path: request.url,
    });
  }
}
票数 2
EN

Stack Overflow用户

发布于 2022-01-06 03:55:44

要回答你的具体问题:

我正在寻找一种方法来运行我的NestJS应用程序,使用nodeJS提供的“--跟踪-警告”标志。有什么方法可以做到这一点吗?还是NestJS提供了类似的功能?

我一直在尝试做同样的事情,而且网上似乎也没有关于如何做到这一点的文档。通过一些尝试和错误,我发现这似乎是可行的:

node --trace-warnings -r source-map-support/register --inspect dist/main

请注意,这不会重新构建您的应用程序(无论是在第一次启动应用程序时,还是通过监视更改),因此您将需要手动进行此操作。调试器是通过--inspect开关启用的,如果不需要调试,请删除它。

票数 2
EN

Stack Overflow用户

发布于 2021-08-20 15:04:42

尝试使用npm响应/请求记录器,如温斯顿或莫西,你会得到很多帮助,相信我。

以下是这些nestjs库的链接

https://github.com/scalio/nest-couchdb

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67584837

复制
相关文章

相似问题

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