node.js - TypeError:在云函数中将循环结构转换为 JSON
问题描述
我正在尝试使用我的颤振应用程序中的 firebase 云功能,但是当我调用它时出现错误:
Unhandled error TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle
at JSON.stringify (<anonymous>)
at write (/workspace/node_modules/firebase-functions/lib/logger.js:12:84)
at Object.log (/workspace/node_modules/firebase-functions/lib/logger.js:45:5)
at /workspace/index.js:23:22
at func (/workspace/node_modules/firebase-functions/lib/providers/https.js:273:32)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
我的功能如下所示:
exports.sendNotif = functions.https.onCall((listId, convName, message) => {
const payload = {
notification: {
title: convName,
body: message,
badge: '1',
sound: 'default'
}
}
listId.forEach(id => {
functions.logger.log(id);
admin.firestore().collection('USERS').doc(listId).get().then(snapshot => {
console.log(snapshot.data().FirebaseToken)
admin.messaging().sendToDevice(snapshot.data().FirebaseToken, payload).then(response => {
console.log('SUCCES')
}).catch(error => { console.log('ERROR') })
})
});
})
我这样称呼它:
sendNotifications() async {
HttpsCallable callable =
FirebaseFunctions.instance.httpsCallable('sendNotif');
await callable.call(
<String, dynamic>{
'listId': ['10571112'],
'convName': 'VYSgames',
'message': 'Test'
},
);
}
解决方案
推荐阅读
- php - PDO 扩展未在 PHP 中加载
- python - 如何在 Python 中的文件行中找到确切的字符串?
- spring - 无法获得与 Java 1.8 的 Impala JDBC 连接
- python - 为什么 dim=1 在 torch.argmax 中返回行索引?
- python-3.x - 如何修复正在打印的多个布尔值
- python - 计算列表中唯一集的数量
- sql-server - 我们可以阻止 SQL Server 忽略值中的尾随空格吗
- sql - 在 Oracle 中,[select * from table()] 是什么意思?
- nuget - 如何使用 Nuget 打包 x86 / x64 特定的 C++/CLI DLL?
- python - 解析嵌套 JSON 列表/字典的问题