Reputation: 1201
I'm using Meteor and angularJS 2 in web application. Please look at the below publication function.
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();
});
Now while subscribe the above publication from angularjs2, I'm using following code:-
// Var declarations
this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe(() => {
// Here subscribe data ready, so I called to other method.
});
The problem is here is that, how could i catch publication function error
'throw new Meteor.Error(403,'UnAuthorized error')'
Upvotes: 1
Views: 157
Reputation: 292
the second argument of subscribe method is error callback, So you can write some condition here.
this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe(() =>{
// Here subscribe data ready, so I called to other method.
},error => console.log('error',error));
Upvotes: 2
Reputation: 543
You can do this in the callback.
this.meteorSubscription = MeteorObservable.subscribe("abc").subscribe((err) => {
if (err){
console.log(err);
}
});
Upvotes: 0