我有一些异步方法需要等待完成,然后才能从请求返回。我正在使用 Promises,但我不断收到错误消息:
Each then() should return a value or throw // promise/always-return
为什么会这样?这是我的代码:
router.get('/account', function(req, res) {
var id = req.user.uid
var myProfile = {}
var profilePromise = new Promise(function(resolve, reject) {
var userRef = firebase.db.collection('users').doc(id)
userRef.get()
.then(doc => { // Error occurs on this line
if (doc.exists) {
var profile = doc.data()
profile.id = doc.id
myProfile = profile
resolve()
} else {
reject(Error("Profile doesn't exist"))
}
})
.catch(error => {
reject(error)
})
})
// More promises further on, which I wait for
})
最佳答案
关于javascript - 使用 Promises 时,每个 then() 都应该返回一个值或抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48750847/