Javascript firebase功能内部服务器和最大sta

Javascript firebase功能内部服务器和最大sta,javascript,firebase,google-cloud-functions,http-status-code-500,Javascript,Firebase,Google Cloud Functions,Http Status Code 500,我的目标是从用户那里获取输入,如果用户经过身份验证且输入长度小于30,则将其存储到基中,然后清除输入并关闭表单。它在后端存储数据,但也会引发此错误 这是firebase日志中的错误 Unhandled error RangeError: Maximum call stack size exceeded at Object (native) at /srv/node_modules/lodash/lodash.js:4919:24 at baseForOwn (/srv/n

我的目标是从用户那里获取输入,如果用户经过身份验证且输入长度小于30,则将其存储到基中,然后清除输入并关闭表单。它在后端存储数据,但也会引发此错误

这是firebase日志中的错误

Unhandled error RangeError: Maximum call stack size exceeded
    at Object (native)
    at /srv/node_modules/lodash/lodash.js:4919:24
    at baseForOwn (/srv/node_modules/lodash/lodash.js:2990:24)
    at Function.mapValues (/srv/node_modules/lodash/lodash.js:13426:7)
    at encode (/srv/node_modules/firebase-functions/lib/providers/https.js:184:18)
    at /srv/node_modules/lodash/lodash.js:13427:38
    at /srv/node_modules/lodash/lodash.js:4925:15
    at baseForOwn (/srv/node_modules/lodash/lodash.js:2990:24)
    at Function.mapValues (/srv/node_modules/lodash/lodash.js:13426:7)
    at encode (/srv/node_modules/firebase-functions/lib/providers/https.js:184:18)
已完成,状态代码为500

这就是它在浏览器中显示的错误

Error: INTERNAL
    at new g (error.ts:66)
    at b (error.ts:175)
    at A.<anonymous> (service.ts:263)
    at tslib.es6.js:100
    at Object.next (tslib.es6.js:81)
    at r (tslib.es6.js:71)
最后,这是firebase函数

// http callable function (adding a request)
exports.addRequest = functions.https.onCall((data,context) => {
    if (!context.auth) {
        throw new functions.https.HttpsError('unauthenticated',"Unauthorized Person not allowed!");
    }
    else if (data.text.length > 30) {
        throw new functions.https.HttpsError('invalid-argument',"Length of string must be less than 30");
    }

    else {
            return admin.firestore().collection("requests").add({
                text :data.text,
                upVote : 0
            }); 
    }
})

可调用函数不应该只返回任何承诺。他们应该返回一个承诺,该承诺与发送给客户机的响应一致。您返回的承诺将在数据库操作完成时解析。请注意,返回一个DocumentReference对象。nodejs无法序列化此对象,因为它包含自引用链接。您需要准确地决定客户应该收到什么

您可以通过返回更具体的内容在短期内解决此问题:

return admin.firestore().collection("requests").add({
    text :data.text,
    upVote : 0
})
.then(() => {
    return { result: "OK" }
})
但最终,您需要定义并实现客户需要接收的内容

另见:


调用云函数后,似乎发生了一些错误。你能解释一下中的回调应该如何工作吗?我从youtube频道netninja学习firebase,我做的和他做的完全一样,但他的代码运行平稳,我的代码给出了这个错误,但我已经解决了,谢谢你的评论如果你觉得这个答案有用,按照惯例,在堆栈上对答案进行投票,并使用答案左侧的按钮将其标记为正确。
// http callable function (adding a request)
exports.addRequest = functions.https.onCall((data,context) => {
    if (!context.auth) {
        throw new functions.https.HttpsError('unauthenticated',"Unauthorized Person not allowed!");
    }
    else if (data.text.length > 30) {
        throw new functions.https.HttpsError('invalid-argument',"Length of string must be less than 30");
    }

    else {
            return admin.firestore().collection("requests").add({
                text :data.text,
                upVote : 0
            }); 
    }
})
return admin.firestore().collection("requests").add({
    text :data.text,
    upVote : 0
})
.then(() => {
    return { result: "OK" }
})