【发布时间】:2018-01-31 04:19:52
【问题描述】:
我正在尝试使用 catch 方法从 Firebase/AngularFire 捕获授权错误,但我收到错误 Property 'catch' does not exist on type 'FirebaseListObservable<any[]>'.
问题是当我无法访问基于身份验证规则的某些数据时。当我通过身份验证时,代码可以工作(没有 .catch,因为这是一个编译错误)。
Records: FirebaseListObservable<any[]>;
constructor(public afAuth: AngularFireAuth, public af: AngularFireDatabase)
{
try {
this.user = afAuth.authState;
this.Records = af.list('/Testing');
}
catch (e) {
console.log((<Error>e).message);//conversion to Error type
}
}
上述方法将起作用。但是,如果 /Testing 由于身份验证规则而无法访问,则会出现异常。我似乎无法用标准的 try/catch 捕捉到这个错误。不过,我确实看到了使用 catch 的参考,
this.Records = af.list('/Testing').catch(e => {
console.log((<Error>e).message);//conversion to Error type
});
但是,这会导致上面的编译错误。
虽然我知道我可以更改 Firebase 读取权限以允许任何人读取数据,但我正在尝试处理此错误情况以使我的代码更安全,以防有人进入正在尝试的应用程序的一部分处理数据,但安全性不允许他们访问数据。
【问题讨论】:
标签: typescript firebase angularfire2