首页 > 解决方案 > 直接调用 Firebase Cloud 函数时出现内部错误

问题描述

尝试直接调用 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),并且我已尝试尽可能地贴近文档。有什么明显的我做错了吗?

谢谢

标签: javascriptfirebasegoogle-cloud-functions

解决方案


我在使用AngularFireFunctions httpsCallable 方法时看到了完全相同的症状。最近将 firebase sdk 从 8.2.4 更新到 8.3.1,我怀疑这会引入 https 可调用内部错误。降级到 8.2.4 解决了这个问题:

npm install firebase@8.2.4 --save


推荐阅读