亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何解決節點上未處理的應答警告?

如何解決節點上未處理的應答警告?

牛魔王的故事 2022-09-23 09:21:00
我正在嘗試制作一個用于學習目的的API。API 沒有任何問題。我得到了我想要的回應。但問題是,當我查看終端時,我得到一個這樣的錯誤:未經處理的應答警告:未經處理的承諾拒絕。此錯誤起源于在沒有 catch 塊的情況下拋入異步函數內部,或者拒絕未使用 .catch() 處理的承諾。它警告我,不處理權限拒絕將終止 Node.js??刂婆_日志 (node:8721) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client    at ServerResponse.setHeader (_http_outgoing.js:526:11)    at ServerResponse.header (/backend/node_modules/express/lib/response.js:771:10)    at ServerResponse.send (/backend/node_modules/express/lib/response.js:170:12)    at ServerResponse.json (/backend/node_modules/express/lib/response.js:267:15)    at exports.apiFormat (/backend/handlers/errorHandlers.js:85:21)    at /backend/middlewares/auth.js:31:11    at allFailed (/backend/node_modules/passport/lib/middleware/authenticate.js:107:18)    at attempt (/backend/node_modules/passport/lib/middleware/authenticate.js:180:28)    at Strategy.strategy.fail (/backend/node_modules/passport/lib/middleware/authenticate.js:302:9)    at verified (/backend/node_modules/passport-local/lib/strategy.js:82:30)    at /backend/middlewares/passport.js:69:24    at processTicksAndRejections (internal/process/task_queues.js:97:5)(node:8721) 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:8721) [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.我為相同的 json reson resonse 格式 api 制作它。( 錯誤處理程序.js)
查看完整描述

1 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

validationResult()返回結果對象,但不返回承諾。您正在使用 等待承諾對象。await

從代碼中刪除以防止錯誤:await

const errors = validationResult(req);// .. and your error variable will have arrays of error.


查看完整回答
反對 回復 2022-09-23
  • 1 回答
  • 0 關注
  • 86 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號