【发布时间】:2020-09-01 14:36:15
【问题描述】:
我有一个 firebase 函数,在该函数中我手动抛出一个错误,其状态和消息如下:
throw new functions.https.HttpsError('permission-denied', 'Token does not match');
我从服务器得到的响应是这样的(使用 chrome 开发控制台):
{"error":{"message":"Token does not match","status":"PERMISSION_DENIED"}}
但是当我这样调用函数时,错误中没有状态(使用 AngularFire2):
try {
return await this.functions.httpsCallable<void, void>('testFunc')().toPromise();
} catch (e) {
console.log(e.name); // "Error"
console.log(e.message); // "Token does not match"
console.log(e.status); // undefined
}
有什么办法可以得到它的状态,因为我宁愿检查if(e.status == 'PERMISSION_DENIED')而不是if(e.message == 'Token does not match')。
【问题讨论】:
标签: javascript angular firebase google-cloud-functions angularfire2