此函数返回一个内部错误,该错误似乎与调用basicDataFromAllData
函数有关。
exports.usersBasicInfoFromIDs = functions.https.onCall((data, context) => {
const basicDataFromAllData = function(allData) {
console.log(allData)
const basicData = {}
const uid = allData.id
basicData[uid].username = allData.username
basicData[uid].first = allData.first
basicData[uid].last = allData.last
return { basicData }
}
const uids = data.ids;
if (!(uids.length > 0)) {
throw new functions.https.HttpsError('invalid-argument', 'Need some UIDs');
}
const fetchUserObjects = function(uids) {
let promises = []
uids.forEach((uid) => {
const promise = admin.database().ref(`/users/${uid}`).once('value')
.then((dataSnapshot) => {
return basicDataFromAllData(dataSnapshot.val())
})
.catch((error) => {
throw new functions.https.HttpsError('Error: ', error.message, error);
});
promises.push(promise)
})
return Promise.all(promises);
}
return fetchUserObjects(uids)
});
这是对Firebase multiple async requests returned via Promises的跟踪。