Javascript NestJS:全局错误处理程序未捕获未处理的承诺拒绝
我正在使用NestJS,我有一个控制器,它从抛出异常的服务调用异步方法,如下所示:Javascript NestJS:全局错误处理程序未捕获未处理的承诺拒绝,javascript,error-handling,promise,nestjs,Javascript,Error Handling,Promise,Nestjs,我正在使用NestJS,我有一个控制器,它从抛出异常的服务调用异步方法,如下所示: @Get('gde/expedientes/:expediente/caratula') async readExpedientesCaratulaFromGDE(@Param('expediente') expediente: string): Promise<readCaratulaResultType> { return await this.client.readExpedient
@Get('gde/expedientes/:expediente/caratula')
async readExpedientesCaratulaFromGDE(@Param('expediente') expediente: string): Promise<readCaratulaResultType> {
return await this.client.readExpedienteCaratula(expediente) // this throws an Exception!
}
我确实抛出了一个没有catch块的异步函数的内部
,但我希望它能被Nest处理。我想开发自己的全局处理程序,并捕获“请求问题:getaddrinfo ENOTFOUND xxx.xxx.xxx”错误
是否有某种方法可以捕获它,或者我应该始终将我的控制器方法包含在
try/catch
块中?看起来您有一个gdeeexceptionfilter
。你能展示一下代码吗?看起来您正在调用的是exception.getStatus()
,它不是一个函数,因此JS正在抛出一个嵌套无法轻松捕获的顶级错误(特别是当您已经处于异常过滤器中时)。看起来您有一个gdeeexceptionfilter
。您能显示该代码吗?看起来您正在调用exception.getStatus()
这不是一个函数,所以JS抛出了一个顶级错误,Nest很难捕捉到这个错误(特别是当您已经处于异常过滤器中时)
problem with request: getaddrinfo ENOTFOUND xxx.xxx.xxx
(node:17518) UnhandledPromiseRejectionWarning: TypeError: exception.getStatus is not a function
at GDEExceptionFilter.catch (/home/sas/devel/apps/trabajo-it/coordinacion/gestion-documental/tramites-consulta/src/api/dist/gde/gde-exception.filter.js:16:34)
at ExceptionsHandler.invokeCustomFilters (/home/sas/devel/apps/trabajo-it/coordinacion/gestion-documental/tramites-consulta/src/api/node_modules/@nestjs/core/exceptions/exceptions-handler.js:33:26)
at ExceptionsHandler.next (/home/sas/devel/apps/trabajo-it/coordinacion/gestion-documental/tramites-consulta/src/api/node_modules/@nestjs/core/exceptions/exceptions-handler.js:13:18)
at /home/sas/devel/apps/trabajo-it/coordinacion/gestion-documental/tramites-consulta/src/api/node_modules/@nestjs/core/router/router-proxy.js:13:35
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:17518) 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(). (rejection id: 1)
(node:17518) [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.