【发布时间】:2021-03-18 10:14:14
【问题描述】:
尝试直接调用 Firebase Cloud Function 时出现以下错误:
Error: internal
at new HttpsErrorImpl (error.ts:65)
at _errorForResponse (error.ts:175)
at Service.<anonymous> (service.ts:276)
at step (tslib.es6.js:102)
at Object.next (tslib.es6.js:83)
at fulfilled (tslib.es6.js:73)
我注意到用户过去曾遇到过由 Firebase 版本 7.22.0 引起的类似问题,并且在 7.22.1 中已解决,但我使用的是 8.3.0,所以不应该这样一个问题。
我的云函数从未被触发,我在 Firebase 函数日志中看不到任何错误。
这是我的客户端函数:
async function testCallFunction() {
const callTest = functions.httpsCallable('callTest');
return await callTest({ companyId: coRef })
.then((result) => {
console.log(result)
}).catch(err => {
console.log(err)
})
}
这是我的云函数:
exports.callTest = functions.https.onCall((data, context) => {
console.log('Call Test Fired')
return admin.firestore().collection('users').doc(context.auth.uid).get()
.then((doc) => { return doc.data()})
.catch(err => {throw new functions.https.HttpsError(err.message)})
})
但它永远不会到达云功能,我只收到内部错误,云功能日志中没有日志。
我不确定我做错了什么?我已确保我使用的是最新的 firebase JS SDK (8.3.0),并且我已尝试尽可能地贴近文档。有什么明显的我做错了吗?
谢谢
【问题讨论】:
-
您的客户端代码一定有问题,否则应该调用云函数并显示一些日志。
-
是的,您似乎需要降级您的 Firebase 版本。试试 7.22.1
-
如果不混合 async/await 然后(不推荐)并执行以下操作会发生什么:
const result = await callTest({ companyId: coRef }); console.log(result);?另外,您的用户在调用该函数时是否经过身份验证?换句话说,context.auth.uid在yoru Cloud Function中是否具有期望值? -
谢谢@JeetChhatrala 我会尝试降级到那个特定的版本,但是当我第一次遇到这个问题时我升级到了8.3.0,但我会试试这个版本,谢谢。
-
@RenaudTarnec 是的,我的用户已通过身份验证,我也尝试过以这种方式处理结果 =,但我也遇到了同样的错误。请记住,无论如何,它永远不会到达实际的云功能。
标签: javascript firebase google-cloud-functions