使用firebase仿真器时调用firebase云函数会导致decored_exceeded错误

发布于 2025-01-26 20:36:01 字数 1086 浏览 3 评论 0原文

我有一个非常简单的云功能,可以返回JSON中的字符串。

const functions = require("firebase-functions");

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions

exports.helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  response.send({data: "Hello from Firebase!"});
});

我称其为这样(App在Android模拟器中运行):

async function callFirebaseCloudFunction() {
    try
    {

        functions().useEmulator('localhost', 5001);
        

        const helloWorldFunction = functions().httpsCallable('abcd');
        const response = await helloWorldFunction();
        console.log(response?.data);
        alert(response?.data);
    }
    catch (error)
    {
        console.log("====",error);
        alert(`${JSON.stringify(error)}` );

    }
}

问题是我正在获得deadline_exceeded错误。

请注意,我还在运行firebase的云功能模拟器,因此此行: functions()。使用Emulator('localhost',5001);

否则,评论上行并调用已部署的函数正常工作。

I've got a very simple cloud function that returns a string in a JSON.

const functions = require("firebase-functions");

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions

exports.helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  response.send({data: "Hello from Firebase!"});
});

And I am calling it like this(app is running in android emulator):

async function callFirebaseCloudFunction() {
    try
    {

        functions().useEmulator('localhost', 5001);
        

        const helloWorldFunction = functions().httpsCallable('abcd');
        const response = await helloWorldFunction();
        console.log(response?.data);
        alert(response?.data);
    }
    catch (error)
    {
        console.log("====",error);
        alert(`${JSON.stringify(error)}` );

    }
}

The issue is that I am getting DEADLINE_EXCEEDED error.

Note that I am also running firebase's emulator for cloud function, therefore this line:
functions().useEmulator('localhost', 5001);

Otherwise, commenting the above line and calling the deployed function works fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光暖心i 2025-02-02 20:36:01

花了一个多小时,并写了这个问题。我终于弄清楚了这个问题(一种),所以我认为我应该回答。

我正在使用Genymotion的Android模拟器,并且请求不断失败“ deadline_exceed”错误。当我使用AVD(来自Android Studio的Android虚拟设备)时,它的工作正常。

After spending more than an hour, and writing this question. I finally figured out the problem(kind of), so I thought I should just answer it.

I was using the android emulator of Genymotion, and the request kept failing "DEADLINE_EXCEEDED" error. When I used avd(android virtual device from Android Studio), it worked totally fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文