![](/img/trans.png)
[英]Getting Internal Error when calling Firebase Cloud Function Directly
[英]Error INTERNAL from Firebase Cloud Function
Firebase Cloud Functions 中有myFunction :
const myFunctionHandler = (params, context) => {
return new Promise((resolve, reject) => {
return admin
.database()
.ref("checks")
.push(params)
.then((r) => resolve(r))
.catch((e) => reject(e));
};
exports.myFunction = functions.https.onCall(myFunctionHandler);
这是我从客户端调用它的方式:
functions()
.httpsCallable('myFunction')({
myParam: true,
})
.then(resp => console.log(resp))
.catch(e => console.log(e));
在 Firebase Cloud Functions 中,这些是日志:
Function execution started
Unhandled error RangeError: Maximum call stack size exceeded
at Function.mapValues (/workspace/node_modules/lodash/lodash.js:13426:7)
at encode (/workspace/node_modules/firebase-functions/lib/providers/https.js:183:18)
at encode (/workspace/node_modules/firebase-functions/lib/providers/https.js:157:16)
at /workspace/node_modules/lodash/lodash.js:13427:38
at /workspace/node_modules/lodash/lodash.js:4925:15
at baseForOwn (/workspace/node_modules/lodash/lodash.js:2990:24)
at baseForOwn (/workspace/node_modules/lodash/lodash.js:2990:24)
at Function.mapValues (/workspace/node_modules/lodash/lodash.js:13426:7)
Function execution took 2438 ms, finished with status code: 500
2438 毫秒后,数据在 Firebase 实时数据库中正确输入,但响应给出[Error: INTERNAL]
。 为什么?
[编辑]
我尝试在客户端复制相同的数据库推送功能,如下所示:
database()
.ref()
.child(`checks`)
.push(params)
.then(r => resolve(r))
.catch(e => reject(e));
我的回应是: https://myApp.firebaseio.com/checks/-MHABiZl5lsDBLSP22-3
: https://myApp.firebaseio.com/checks/-MHABiZl5lsDBLSP22-3
这是一个积极的反馈,告诉我信息存储正确。
我从 Cloud Functions 得到了同样的积极响应,但我得到的是[Error: INTERNAL]
。
接收(从 Firebase 云函数中的函数)一个错误作为响应我的想法是信息没有正确存储。
可调用函数向客户端发送 JSON 负载。 这就是他们可以发送的全部内容。 当您从可调用函数返回承诺时,它将尝试序列化从承诺解析的对象。 您尝试发送的对象( push()的结果是ThennableReference )对于序列化来说太复杂了,所以它失败了。 它包含自引用链接,这会导致您看到的错误。
您的问题仍然没有准确指出 JSON 有效负载应该是什么。 您将不得不弄清楚那是什么,并且只将该对象发送给客户端。 它显然不能是一个 ThennableReference。 如果您需要将其转换为某些东西,请弄清楚如何转换它,然后发送该对象。
相同的函数从以太客户端或服务器给出不同的响应。 在 FCF 中,我只是避免使用它来解析推送的响应。 在客户端,它返回 google 文档中描述的 https 链接。
还要确保 localhost:5001 节点服务器没有运行。 在我的情况下干扰了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.