javascript - 你能读懂 firebase 函数的 HttpsError 状态吗?
问题描述
我有一个 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')
.
解决方案
e
将是一个HttpsError对象。正如您从 API 文档中看到的那样,它应该有一个名为FunctionsErrorCodecode
对象的属性,其中包含作为字符串的 HTTP 状态代码,该字符串应该与您从可调用函数中抛出的内容相匹配。所以我希望成为 string 。e.code
permission-denied
推荐阅读
- python - 原来的链表改变了
- openlayers - 更改现有(矢量切片)图层的渲染模式
- .net - 在 Masstransit 中使用 rabbitmq 传输时如何为生产者和消费者创建两个 rabbitmq 连接
- spring-boot - Spring Boot 测试:未加载 JavaMailSender 属性
- c++ - 跨不同着色器使用多个 image2d 的问题
- asp.net - 如何取消选中 ASP.NET/VB.NET 上的 RadioButton
- javascript - 我在 Acrobat 中的 JavaScript 大部分时间都在运行
- javascript - 未捕获的 ReferenceError: $event 未定义
- python - 如何用子类内部状态包装所有 python 超类方法?
- javascript - FastCGI 提供的页面上的 Javascript 未定义函数