【发布时间】:2022-09-30 03:39:25
【问题描述】:
main.controller.ts:135
throw new NotFoundException(\'Swap not found\');
^
NotFoundException: Swap not found
我在控制器中有一个非常简单的请求
@Get(\"/details\")
@ApiResponse({
status: 200,
description: \'Returns the details\',
})
async getDetails(
@Query(\'id\') id: string
): Promise<Result> {
let details = await this.databaseService.find(id)
if (!details) {
throw new NotFoundException(\'Swap not found\');
}
return {
details: details,
}
}
抛出异常后,NestJS 也停止运行了!? 我该如何避免这种情况?我知道异常过滤器,但那是针对自定义异常的,对吧?我使用默认的。
不过,以防万一,我添加了一个全局变量来测试和相同的行为:app.useGlobalFilters(new HttpExceptionFilter());
这是预期的行为吗?
-
这很奇怪。默认行为是捕获该异常并回复 500 错误。你能提供一些重现这个的minimum repo吗?
-
我确实在崩溃之前得到了 json( statusCode: 404 )。之后的任何请求都没有到达服务器 ERR_CONNECTION_REFUSED
-
那 sn-p 看起来不错。你不应该因为这种模式而崩溃。如果您分享一些完整的代码,我会帮助您。你可以用这个开始构建它:gitlab.com/micalevisk/minimum-reproduction--nestjs-v8
-
哦,那太好了,肯定会节省我一些时间!谢谢!我会用叉子回复你
-
奇怪,它与我在那个仓库中的代码一起工作。
标签: nestjs