【问题标题】:"severity":"WARNING","message":"Request has invalid method. GET"severity":"WARNING","message":"请求的方法无效。GET
【发布时间】:2021-07-30 07:17:04
【问题描述】:

最少的代码:

exports.test = functions.https.onCall((data, context) => {
  throw new functions.https.HttpsError('failed-precondition', 'My error message');
});

当我跑步时

firebase emulators:start

我得到以下链接:

✔ 函数[us-central1-test]:http 函数已初始化(http://localhost:5001/project/us-central1/test)。

点击后出现如下错误:

i  functions: Beginning execution of "us-central1-test"
>  {"severity":"WARNING","message":"Request has invalid method. GET"}
>  {"severity":"ERROR","message":"Invalid request, unable to process."}
i  functions: Finished "us-central1-test" in ~1s

我期待failed-preconditionMy error message。我做错了什么?

PS:我已经检查了其他答案,但我认为我的代码有问题。

【问题讨论】:

  • 问题是我通过 HTTP 调用可调用函数(这需要实现协议,就像我必须将 data 传递给它)。但是,上述代码使用 Firebase Client SDK 可调用帮助程序运行良好。

标签: javascript firebase google-cloud-functions


【解决方案1】:

也许你需要在你的“throw new”之前添加“return”?

我自己也有类似的问题,但据我了解,数据应该从承诺中返回。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
  • 抛出错误时不需要return
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-15
  • 2013-05-28
  • 2020-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多