2017-03-17 84 views
1

我在web应用程序中使用Meteor和angularJS 2。请看下面的出版物功能。流星发布错误检测

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上述出版物中,我使用下面的代码: -

//瓦尔声明

this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe(() => { 
    // Here subscribe data ready, so I called to other method. 
}); 

的问题是这里要说的是,我怎么能赶上发布功能错误

'抛出新的Meteor.Error(403,'未授权错误')'

回答

1

subscribe方法的第二个参数是错误回调,所以你可以在这里写一些条件。

this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe(() =>{ 
    // Here subscribe data ready, so I called to other method. 
},error => console.log('error',error)); 
0

您可以在回调中执行此操作。

this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe((err) => { 
    if (err){ 
     console.log(err); 
    } 
}); 
+0

好的谢谢。但我如何跟踪错误?我已阅读onReady和onStop函数。当我在subscribe()中调用任何functin时,onReady成功调用。 – Shubham

+0

我的答案工作?这个问题出现在发布中,所以在抛出错误之前添加一个'console.log(this.userId)'。 – mutdmour

+0

不,发布功能没有问题。假设有任何错误发生,我想抛出该错误。而不是如何在订阅功能中捕获客户端的错误。 – Shubham