最少代码:
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-precondition
和My error message
。我做错了什么?
PS:我已经检查过其他答案,但我认为我的代码有问题。
也许你需要在“扔新”之前添加“返回”?
我自己也遇到类似的问题,但据我了解,数据应该从承诺中返回。
此错误消息 (
Request has invalid method. GET
) 的根本原因是因为 firebase 云函数使用 POST
方法。
当您单击链接时,它会打开浏览器,然后使用
GET
方法而不是 POST
。
要在模拟器上测试云功能,您可以:
# start the Firebase Emulators
firebase emulators:start
# trigger the emulated task queue function
curl \
-X POST # An HTTP POST request...
-H "content-type: application/json" \ # ... with a JSON body
http://localhost:$PORT/$PROJECT_ID/$REGION/$NAME \ # ... to function url
-d '{"data": { ... some data .... }}' # ... with JSON encoded data
重要要求(已在上面的代码片段中):