第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

UnhandledPromiseRejectionWarning: ReferenceError:

UnhandledPromiseRejectionWarning: ReferenceError:

繁星點點滴滴 2021-11-18 20:40:32
我正在嘗試創(chuàng)建一個輔助方法以在同一個控制器中使用:module.exports = {  async update(req, res) {    // code here...    // method call    this.verifyItemInStock()    // more code here ...  },  // method declaration  verifyItemInStock (itemId) {      // more code...  }}但我收到以下錯誤:(node:31904) UnhandledPromiseRejectionWarning: ReferenceError: verifyItemInStock is not defined at update (/home/netogerbi/workspaces/zombieresistance/zombieresistance/app/controllers/trade.controller.js:34:5) (node:31904) UnhandledPromiseRejection promiseWarning: Unhandled拒絕。這個錯誤要么是因為在沒有 catch 塊的情況下拋出了異步函數(shù),要么是因為拒絕了一個沒有用 .catch() 處理過的承諾。(rejection id: 1) (node:31904) [DEP0018] DeprecationWarning:不推薦使用未處理的承諾拒絕。將來,未處理的承諾拒絕將使用非零退出代碼終止 Node.js 進(jìn)程。
查看完整描述

2 回答

?
縹緲止盈

TA貢獻(xiàn)2041條經(jīng)驗 獲得超4個贊

刪除this并使其更具可讀性:


// method declaration

const verifyItemInStock = itemId => {

  // more code...

}


const update = async (req, res) => {

  // code here...

  // method call

  verifyItemInStock()

  // more code here ...

}



module.exports = {

  update,

  verifyItemInStock,

}

此外,承諾的消費者應(yīng)該有一個問題:


import { update } from './my-module';


update(req, res).then(...).catch(...)

// or

try {

  const resolved = await update(req, res);

  // consume the resolved value

} catch (e) {

  // exception handling

}


查看完整回答
反對 回復(fù) 2021-11-18
?
翻過高山走不出你

TA貢獻(xiàn)1875條經(jīng)驗 獲得超3個贊

我通過以下方式解決:


const update = async (req, res) => {


  // auxiliar method declaration

  verifyItemInStock = itemId => {

      // code...

  }


  // ...

  // method call

  const hasItems = verifyItemInStock(id)


}


查看完整回答
反對 回復(fù) 2021-11-18
  • 2 回答
  • 0 關(guān)注
  • 238 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號