Javascript 流星发布错误检测
我在web应用程序中使用Meteor和AngularJS2。请查看下面的发布功能Javascript 流星发布错误检测,javascript,angular,meteor,angular-meteor,Javascript,Angular,Meteor,Angular Meteor,我在web应用程序中使用Meteor和AngularJS2。请查看下面的发布功能 Meteor.publish('abc', function () { // For throwing the meteor error according to the condition if(!this.userId) throw new Meteor.Error(403,'UnAuthorized error'); // Returning the collection. return collec
Meteor.publish('abc', function () {
// For throwing the meteor error according to the condition
if(!this.userId) throw new Meteor.Error(403,'UnAuthorized error');
// Returning the collection.
return collection.find();
});
现在,在从angularjs2订阅上述出版物的同时,我使用以下代码:-
//Var声明
this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe(() => {
// Here subscribe data ready, so I called to other method.
});
这里的问题是,如何捕获发布函数错误
'抛出新流星。错误(403,'未经授权的错误')'
您可以在回调中执行此操作
this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe((err) => {
if (err){
console.log(err);
}
});
subscribe方法的第二个参数是error callback,因此可以在这里编写一些条件
this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe(() =>{
// Here subscribe data ready, so I called to other method.
},error => console.log('error',error));
好的,谢谢。但我如何跟踪错误呢?我已经读过onReady和onStop函数。当我调用subscribe()中的任何functin时,onReady调用成功。我的答案有效吗?问题在发布中,因此在抛出错误之前添加
console.log(this.userId)
。否,发布函数中没有问题。假设捕获到任何错误,我想抛出该错误。不是我如何在订阅功能中捕捉客户端的错误。对不起,我误解了这个问题,这里有一个更新。