我有以下错误:
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\`
发布于 2022-03-23 15:49:38
首先,声明新对象不需要await
,所以将声明新用户更改为const user = new User(your_object_here)
在catch()中的含义,然后抛出错误并再次捕获。将代码更改为此,然后再试一次
try{
// logic here
res.send('ok')
}catch(error) {
console.log('that did not go well');
res.status(500).send('fail')
}
https://stackoverflow.com/questions/71589843
复制相似问题