【发布时间】:2018-10-29 12:09:05
【问题描述】:
如何故意让承诺失败?有时我只是跳过测试并假设一切都很好,但我想故意做出失败的承诺,以便我的捕获起作用。
exports.submitJob = async (req, res, next) => {
const { cv } = req.body
const userId = req.user._id
try {
if(!cv) {
//how to pass error to catch block?
}
const save_submission = new Submission({
userId,
cv
}).save()
} catch(e => {
res.json({
status: 0,
error: e
})
})
next()
}
【问题讨论】:
-
您是否尝试抛出错误?