javascript - 为什么这个 Firebase Function Promise 没有返回正确的错误?
问题描述
这是我正在编写的测试 Firebase 函数:我已经知道 ref.child(uuid) 在我的实时数据库中不存在。
ref.child(uuid).once('value')
.then((user) => {
if (!user.exists()) {
console.log("Throwing, User not found")
throw new Error("Error: No record with this UUID in Database");
}
//Get the node for the given provider (twitter, google or facebook)
if (user.child(provider).exists())
return (user.child(provider).val().status)
else
throw new Error("Error: Login node does not exist for this provider");
})
.then((result) => res.status(200).json({status: result}))
.catch((error) => res.status(400).json({error_msg: error}));
输出
Throwing, User not found
400, {"error_msg": {}}
所以该throw new Error()
行运行了,但捕获不知何故没有从“错误”参数中获取错误消息。
这怎么可能?
解决方案
构造Error
函数包含两个属性message
,name
因此更改:
{error_msg: error}
进入这个:
{error_msg: error.message}
作为参考,请检查以下内容:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
推荐阅读
- database - redis LUA脚本delete -call delete VS scan unlink
- arrays - 数组数据读取失败
- spring - 是否可以监视应用程序上下文中的每个 bean?
- google-sheets - 逐行转置表格
- python - Django 表单请求方法始终是 GET,甚至在 HTML 模板中提到了 method=“POST”
- list - 扑; 小部件的排序列表
- git - Git Revert 导致合并冲突虽然没有?
- backup - 点燃从备份节点读取过时的数据
- azure - Azure 容器注册表 - 401 未经授权的错误
- firebase - Flutter 登录如何使用 Snackbar 显示 FirebaseAuthException 消息