gpt4 book ai didi

node.js - Firebase 云函数说 Unreachable 并且每个 then() 应该返回一个值或抛出 promise/always-return

转载 作者:搜寻专家 更新时间:2023-10-31 23:31:12 25 4
gpt4 key购买 nike

Firebase 云函数的 Javascript 代码给出了为推送通知编写的错误

索引.js

'use strict'
//Install functions and admin sdks'
const functions = require('firebase-functions');
const admin =require('firebase-admin');

admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.database.ref('/notifications/{user_id}/{notification_id}').onWrite((change, context) => {
//onwrite will run if data changed
const user_id = context.params.user_id;
const notification = context.params.notification;

if (context.params === null) {
return console.log("Notification Has Been Deleted");
}
let token_id = null;
const deviceToken = admin.database.ref(`/Users/${user_id}/device_token`).once('value');
return deviceToken.then(result => {

token_id = result.val();

const payload = {
notification:{
title:"Friend Request",
body:"You have recieved a new friend request",
icon:"default"
}
};


});


return admin.messaging().sendToDevice(token_id, payload).then(response =>{
console.log('This is the notify feature');
}).catch(err => {
console.log('Error getting documents', err);
});

});

运行 firebase deploy 命令时出现如下错误。如果有人可以支持,我将不胜感激。

错误

error 每个 then() 应该返回一个值或抛出 promise/always-returnerror 无法访问的代码 no-unreachableerror 每个 then() 应该返回一个值或抛出 promise/always-return

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

最佳答案

希望一切顺利,你应该这样回来

return console.log('This is the notify feature');

关于node.js - Firebase 云函数说 Unreachable 并且每个 then() 应该返回一个值或抛出 promise/always-return,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49841484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com