这是我正在编写的一个测试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()
行已运行,但是catch却以某种方式无法从“错误”参数中获取错误消息。
这怎么可能?
该Error
构造函数包含两个属性message
和name
因此改变:
{error_msg: error}
到这个:
{error_msg: error.message}
作为参考,请检查以下内容:
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Error
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句