Firebase:如何从httpsCallable处理HttpsError('ok')?

时间:2020-10-24 00:36:40

标签: firebase google-cloud-functions

我的测试Firebase Function除了“ ok”抛出HttpsError之外什么也没做:

exports.UpdateLobby = functions.https.onCall(async (data, context) => {
    throw new functions.https.HttpsError('ok', 'test', 'test2');
}

我的Node.js测试器应用程序调用该函数并尝试处理响应:

var testFirebaseFunction = firebase.functions().httpsCallable("UpdateLobby");
return testFirebaseFunction().then(function(result) {
    console.log(JSON.stringify(result));
    return;
}).catch(function(error) {
    console.log(JSON.stringify(error, Object.getOwnPropertyNames(error)));
}

但是错误处理程序总是会触发并包含以下错误:

{"message":"Response is missing data field.","code":"internal"}

documentation表示错误代码'ok'将状态设置为200,并在结果中设置错误字段。

我希望触发“ then”代码路径而不是“ catch”路径。而且如果catch路径触发了,我希望我的错误代码,消息和详细信息会包含在错误中。

该异常表明它期望设置“数据”字段。文档说“确定”将设置“错误”字段。这只是HttpsCallable中的一个错误,状态为200,但设置了错误字段吗?

我应该注意,如果我将错误代码更改为“ ok”以外的任何值(例如,“ invalid-argument”),那么一切都会按预期进行:“ catch”代码路径运行并且错误包含代码,消息,以及详细信息。

0 个答案:

没有答案
相关问题