【发布时间】:2020-12-28 02:57:49
【问题描述】:
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 这是一个积极的反馈,告诉我信息已正确存储。
我从 Cloud Functions 获得了同样的积极响应但是我所拥有的是 [Error: INTERNAL]。
接收(来自 Firebase Cloud Functions 中的函数)一个错误作为响应,我的想法是信息存储不正确。
【问题讨论】:
-
这里没有足够的信息。您希望发送给客户的究竟是什么?您是否尝试过在发送之前记录您发送的内容?如果您查看
push()返回的内容可能会有所帮助。 firebase.google.com/docs/reference/admin/node/… -
push()在客户端上完美运行。在 FCF 上返回此错误。我希望将 http 链接作为响应返回(作为您共享的链接),而不是内部错误。参数不是问题,因为我在数据库中看到它们... -
您希望发送给客户的究竟是什么?
-
我会提供此信息,因为我没有看到引发异常的代码区域。我在这里看到一般错误:stackoverflow.com/questions/52561349/…
-
@DougStevenson 我希望响应此处描述的 http 链接 (firebase.google.com/docs/reference/admin/node/…)。
标签: javascript react-native firebase-realtime-database google-cloud-functions