I've defined a Firebase cloud function that executes upon realtime database onCreate trigger. The function performs it's intended algorithm perfectly except that the logs always show the error: Function returned undefined, expected Promise or value. I've already tried so many things, but I still can't get that error to go away. The important snippets of the code is below.
I've already properly returned a promise. Any ideas how to make the error go away?
index.js
const sendNotificationMessageModule = require('./sendNotificationMessage');
exports.sendNotificationMessage = functions.database.ref( '/Notifications/{pushId}').onCreate((snapshot, context) => {
sendNotificationMessageModule.sendNotificationMessage(snapshot, context, db, admin);
});
sendNotificationMessage.js
First parts of the code:
exports.sendNotificationMessage = function(snapshot, context, db, admin) {
.
.
.
Last parts of the code:
if(...) {
.
.
.
var androidNode = {};
androidNode[constants.propertyNotificationString] = notificationNode;
message[constants.propertyAndroidString] = androidNode;
return admin.messaging().send(message)
.then((response) => {
console.log('Successfully sent message:', response);
return snapshotNotificationMessage.ref.remove();
})
.catch((error) => {
console.log('Error sending message:', error);
});
}
As you can see, the message was successfully sent, but the error is still there. And of course, the data in the realtime database was also successfully removed.
