Javascript firebase功能内部服务器和最大sta
我的目标是从用户那里获取输入,如果用户经过身份验证且输入长度小于30,则将其存储到基中,然后清除输入并关闭表单。它在后端存储数据,但也会引发此错误 这是firebase日志中的错误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
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" }
})
但最终,您需要定义并实现客户需要接收的内容
另见:
// 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" }
})