error Expected catch() or return promise/catch-or-return
23:13 error Each then() should return a value or throw promise/always-return
28:13 error Expected catch() or return promise/catch-or-return
28:13 warning Avoid nesting promises promise/no-nesting
33:21 error Each then() should return a value or throw promise/always-return
45:19 warning Avoid nesting promises promise/no-nesting
45 :19 warning Avoid nesting promises promise/no-nesting
48:27 error Each then() should return a value or throw '
以上代码为错误内容(Mac OS终端), 由于终端已部署, 显示此错误代码。
我遵循firebase的内容并阅读了一段时间,但我不知道。 Firebase证明: “将消息发送到特定设备 要将消息发送到一个特定的设备,请转发该设备的注册令牌,如下所示。有关注册令牌的更多信息,请参阅关于平台的客户端设置。”
我正在使用FCM推送消息,但仅已部署,此代码显示 该代码显示将消息推送到指定人的uid。
一些错误令我困扰, 这是我的代码(正好是其他人的代码(flutter FCM演示)
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp()
exports.sendNotification = functions.firestore
.document('messages/{groupId1}/{groupId2}/{message}')
.onCreate((snap, context) => {
console.log('----------------start function--------------------')
const doc = snap.data()
console.log(doc)
const idFrom = doc.idFrom
const idTo = doc.idTo
const contentMessage = doc.content
// Get push token user to (receive)
admin
.firestore()
.collection('user')
.where('uid', '==', idTo)
.get()
.then(querySnapshot => {
querySnapshot.forEach(userTo => {
console.log(`Found user to: ${userTo.data().nickname}`)
if (userTo.data().pushToken && userTo.data().chattingWith !== idFrom) {
// Get info user from (sent)
admin
.firestore()
.collection('users')
.where('id', '==', idFrom)
.get()
.then(querySnapshot2 => {
querySnapshot2.forEach(userFrom => {
console.log(`Found user from: ${userFrom.data().nickname}`)
const payload = {
notification: {
title: `You have a message from "${userFrom.data().nickname}"`,
body: contentMessage,
badge: '1',
sound: 'default'
}
}
// Let push to the target device
admin
.messaging()
.sendToDevice(userTo.data().pushToken, payload)
.then(response => {
console.log('Successfully sent message:', response)
})
.catch(error => {
console.log('Error sending message:', error)
})
})
})
} else {
console.log('Can not find pushToken target user')
}
})
})
return null
})