短版本:,我正在寻找一种使用nodeJS提供的“--跟踪警告”标志来运行我的NestJS应用程序的方法。有什么方法可以做到这一点吗?还是NestJS提供了类似的功能?
长版本:
嗨!这里是NestJS noob。我正在尝试运行我正在开发的NestJS应用程序的开发版本。但是,在启动应用程序时,我会看到下面的错误。
很明显,它在某个地方遗漏了一个追赶错误!然而,开发版本有很多更新,这个错误可以出现在任何地方,所以我希望有一种更有效的方法来发现这个错误,而不仅仅是检查每个新函数!在错误消息中,有一些关于启动应用程序(node --trace-warnings ...
)时要运行的标志的提示。但是,这些是针对节点而不是NestJS的。
因此,我的问题是,有什么方法可以使用--跟踪警告标志来运行NestJS,还是有其他有效的方法来找出我遗漏了什么地方的追赶错误?
提前感谢!
错误:
(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)
发布于 2021-05-24 21:42:50
嗯,6379是Redis的默认端口,似乎Nest无法连接到它:)
顺便说一句,看看这段话:https://docs.nestjs.com/exception-filters#catch-everything
为了捕获每个未处理的异常(不管异常类型如何),将@
()装饰器的参数列表保留为空,例如@ 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,
});
}
}
发布于 2022-01-06 03:55:44
要回答你的具体问题:
我正在寻找一种方法来运行我的NestJS应用程序,使用nodeJS提供的“--跟踪-警告”标志。有什么方法可以做到这一点吗?还是NestJS提供了类似的功能?
我一直在尝试做同样的事情,而且网上似乎也没有关于如何做到这一点的文档。通过一些尝试和错误,我发现这似乎是可行的:
node --trace-warnings -r source-map-support/register --inspect dist/main
请注意,这不会重新构建您的应用程序(无论是在第一次启动应用程序时,还是通过监视更改),因此您将需要手动进行此操作。调试器是通过--inspect
开关启用的,如果不需要调试,请删除它。
发布于 2021-08-20 15:04:42
https://stackoverflow.com/questions/67584837
复制相似问题