AngularFire2 (@angular/fire) 如何从可调用函数中获取错误?



我正在尝试使用角度火包在 Angular 环境中访问可调用函数的错误消息。请参阅以下代码:

角度(客户端(

async myCallableFunction(id: string) {
try {
const res = await this.afFunctions.httpsCallable('callableFunction')({
id
}).toPromise();
console.log(res);
} catch (err) {
console.error('Error is:', err);
}
}

服务器端(Firebase 功能(

exports.callableFunction = functions.https.onCall((data: {
id: string
}, context: https.CallableContext) => {
// throw error for testing only
throw new https.HttpsError('unknown', 'Test Error Message');
});

记录到控制台的错误消息是:

[console.error]: "error is:" { "code": "unknown", "行": 100205, "列": 32, "源网址": "http://192.168.1.100:8100/vendor.js" }

如何从云火店的响应中访问错误消息

提前谢谢。

在过去的一个小时里,我一直被这个问题困住了,所以我会为那些在这里徘徊的人发布我的答案:

console.error('Error is:', err);

不显示 err 对象的全部内容。 如果要访问 3 个参数中的任何一个,如果 err 对象,则必须直接访问它们:

console.error(e.code);
console.error(e.message);
console.error(e.details);

最新更新