【问题标题】:Firebase cloud messaging Each then() should return a value or throw promise/always-returnFirebase 云消息传递每个 then() 都应该返回一个值或抛出 promise/always-return
【发布时间】:2019-02-19 14:55:11
【问题描述】:

我正在为我的 android 应用程序编写一个用于 firebase 的云功能。我无法解决此错误。我是个新手。

29:73 错误每个 then() 都应该返回一个值或抛出 promise/always-return

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/comment')
 .onWrite((change, context) => {

     // get user ids
     const reciever_id = context.params.reciever_id;
     const sender_id = context.params.sender_id;
     const comment = context.params.comment;
     const object_id = context.params.object_id;
     const objecttype = context.params.objecttype;

     //get the token of reciever 
     return admin.database().ref("/users/" + reciever_id).once('value').then(snap => {
         const token = snap.child("token").val();
         // Create a payload
         var payload = {
             data: {
                 data_type: "direct_message",
                 title: "Comment from" + sender_id,
                 comment: comment,
                 object_id: object_id,
                 objecttype: objecttype,
             }
         };

         // Sent To device with token Id : THIS IS LINE 29
         return admin.messaging().sendToDevice(token, payload).then(response => {
             console.log("Successfully sent message:", response);})
            .catch(error => {console.log("Error:", error); });

});  // token

}); // onWrite

【问题讨论】:

  • 如果您在谷歌上搜索该错误消息,搜索结果是否提供了有关如何最好地使用 Promise 的任何有用信息?
  • 部署工作已成功!你可以看到答案..!我正在关注一个教程,我的功能已上传到 firebase,但它的日志给出了一个错误,所以我删除了它并再次启动云功能的过程..然后我在部署时遇到了错误,但情况并非如此..我很困惑,因为之前上传了相同的代码..!

标签: javascript android firebase firebase-cloud-messaging google-cloud-functions


【解决方案1】:

它工作了,我只是改变了这个

    // Sent To device with token Id
         return admin.messaging().sendToDevice(token, payload).then(result => {
            return console.log("Successfully sent message:", result);
         })

【讨论】:

    猜你喜欢
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 2020-04-02
    相关资源
    最近更新 更多