javascript - NestJS 和 Express 导致间歇性 UnhandledPromiseRejectionWarning
问题描述
我不能因为我的生活无法弄清楚这一点。它经常发生一次,不会导致应用程序本身出现任何问题,但我不知道是什么原因造成的。如果这与它有任何关系,我会从浏览器同时调用 api。
[Nest] 16608 - 11/7/2018, 1:23:08 PM [NestApplication] Nest application successfully started
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/pending-count +14943ms
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/revision-count +16ms
(node:14968) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:469:11)
at ServerResponse.header (C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\express\lib\response.js:767:10)
at ServerResponse.send (C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\express\lib\response.js:170:12)
at ServerResponse.json (C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\express\lib\response.js:267:15)
at ExpressAdapter.reply (C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\@nestjs\core\adapters\express-adapter.js:44:52)
at ExceptionsHandler.catch (C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\@nestjs\core\exceptions\base-exception-filter.js:16:33)
at ExceptionsHandler.next (C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\@nestjs\core\exceptions\exceptions-handler.js:15:20)
at C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\@nestjs\core\router\router-proxy.js:23:35
at Layer.handle_error (C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\express\lib\router\layer.js:71:5)
at trim_prefix (C:\Users\Ricardo Saracino\IdeaProjects\sor-api\node_modules\express\lib\router\index.js:315:13)
(node:14968) 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:14968) [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.
我已经将调用减少到一个非常简单的函数,并确保调用返回一个唯一值(我认为这可能是 304 问题)
@Get('revision-count')
async countRevisions(@User() user, @Param() params) {
user.count ++;
return {
status: 'success',
data: {
rand: user.count,
}
};
}
这是在中间件之前发生的
解决方案
推荐阅读
- r - 使用 r 重新排列数据
- spring - 无法将我的 springboot docker 与我的 cassandra docker 连接起来
- javascript - puppeteer .Click('.classname') 每 20 次尝试仅工作 1 次
- javascript - 数组是 JS 中唯一的 0(1) 数据结构吗?如果是这样,为什么最重要的答案会声称不同?
- c++ - 如何在 JNI 中实例化接口或解决它?
- java - Spring Security - 角色
- java - 使用 sqlite 和 andorid studio 将多个值保存到数组中
- python - “列表”对象没有属性“角度”
- typescript - 如何将定义的字符串常量分配给类型 [Typescript]
- flutter - 如何在复选框单击时显示 AlertDialog