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

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

UnhandledPromiseRejectionWarning:TypeError:

UnhandledPromiseRejectionWarning:TypeError:

泛舟湖上清波郎朗 2023-09-28 10:16:35
當我 console.log(response) 然后我在終端上得到結果,但是當我使用 res.status(200).json(response); 時 我在 nextjs 項目中遇到此錯誤 &未找到在瀏覽器上router.get("/api/backendData", async (req, res, next) => {  dbConnect();  try {    Shop.find().then((response) => {      res.status(200).json(response);      response;      console.log("responseess", response);    });  } catch (e) {    console.log("Error From API Endpoint", e);  }});錯誤代碼:(節點:62307)UnhandledPromiseRejectionWarning:TypeError:res.status不是函數┃位于/home/mh/Documents/Shopiy/shopyy_mode/server/server.js:34:11┃位于processTicksAndRejections(內部/process/task_queues.js: 93:5) ┃ (用于node --trace-warnings ...顯示創建警告的位置) ┃ (節點:62307) UnhandledPromiseRejectionWarning:未處理的承諾拒絕。此錯誤的根源是在沒有 catch 塊的情況下拋出異步函數內部,或者拒絕未使用 .catch() 處理的 Promise。要在未處理的 Promise 拒絕時終止節點進程,請使用 CLI 標志 --unhandled-rejections=strict(請參閱 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。(拒絕 ID: 1) ┃ (節點:62307) [DEP0018] DeprecationWarning: 未處理的承諾拒絕已被棄用。將來,未處理的 Promise 拒絕將會以非零退出代碼終止 Node.js 進程。
查看完整描述

1 回答

?
浮云間

TA貢獻1829條經驗 獲得超4個贊

Koa 路由器不返回 (req, res) 而是返回上下文

https://github.com/ZijianHe/koa-router#router-

router.get('/', (ctx, next) => {

  ctx.res.statusCode = 200

  ctx.body = 'your json data'

})


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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