简短版本: 我正在寻找一种使用 nodeJS 提供的“--trace-warnings”标志运行我的 NestJS 应用程序的方法。有没有办法做到这一点,或者 NestJS 是否提供类似的东西?
长版:
嗨! NestJS 菜鸟在这里。我正在尝试运行我正在开发的 NestJS 应用程序的开发版本。但是,在启动应用程序时,我收到以下错误。
很明显,它在某处遗漏了一个捕获错误!然而,开发版本有很多更新,这个错误可能在任何地方,所以我希望有一种更有效的方法来找到这个错误,而不仅仅是检查每个新功能!在错误消息中,有一些关于启动应用程序时要运行的标志的提示 (node --trace-warnings ...
)。但是,这些是针对 node 而不是 NestJS。
所以我的问题是;有什么方法可以使用 --trace-warnings 标志运行 NestJS 或其他一些有效的方法来找到我遗漏了 catcherror 的位置吗?
提前致谢!
错误:
(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)
答案 0 :(得分:0)
好吧,6379 是 Redis 默认端口,看来 Nest 无法连接到它 :)
顺便说一下,看看这一段: https://docs.nestjs.com/exception-filters#catch-everything
<块引用>为了捕获每个未处理的异常(不管 异常类型),将@Catch() 装饰器的参数列表留空, 例如,@Catch().
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,
});
}
}