当我查看来自Firebase云功能的日志时,我注意到某些功能在日志中有错误,描述为“SYSTEM_ERROR:系统遇到意外错误。功能被杀。”,直到昨天,这种行为不是,这里是其中一个功能。我该如何解决?
const functions = require('firebase-functions');
const admin = require('firebase-admin');
module.exports = functions.database.ref('/cards/{cardID}/interestedUsers').onWrite(event => {
const cardID = event.params.cardID;
console.log("interestedUsers", event.data.val(), cardID);
var currentInterestedUsers = [];
currentInterestedUsers = event.data.val();
var previousInterestedUsers = [];
previousInterestedUsers = event.data.previous.val();
if (event.data.previous.val() && currentInterestedUsers) {
var isNewPendingRequest = false;
if (currentInterestedUsers.length < previousInterestedUsers.length) {
currentInterestedUsers.forEach((interestedUser, index) => {
const interestedUserVal = interestedUser.val();
const isApproved = interestedUser["isApproved"];
console.log("result", interestedUser.val(), interestedUserVal);
if (isApproved == false) {
isNewPendingRequest = true;
}
});
}
if (isNewPendingRequest == false) {
const cardRef = admin.database().ref("cards").child(cardID);
const setupIsNewPendingRequestPromise = cardRef.update({
"isNewPendingRequest": false
});
return Promise.all([setupIsNewPendingRequestPromise]);
};
return console.log("interestedUsers deleting");
};
if (event.data.val() == null) {
console.log("event.data.val() == null");
const cardRef = admin.database().ref("cards").child(cardID);
// check card
const cardCheckPromise = cardRef.once("value", function(cardCheckPromiseSnap, error){
if (error) {
return console.log("cardCheckPromise", error);
};
if (cardCheckPromiseSnap.val()) {
const checkCardID = cardCheckPromiseSnap.val()["id"];
if (checkCardID) {
console.log("checkCardID", checkCardID);
const setupIsNewPendingRequestPromise = cardRef.update({
"isNewPendingRequest": false
});
return Promise.all([setupIsNewPendingRequestPromise]);
} else {
return console.log("checkCardID == null");
}
} else {
return console.log("cardCheckPromiseSnap.val() == null");
};
});
return Promise.all([cardCheckPromise]).catch(function(cardCheckPromiseError){
console.log("cardCheckPromise error", cardCheckPromiseError.message, cardCheckPromiseError.messageId)
});
}
return console.log("just update or adding a new interested user");
});