Search code examples
javascriptangularmeteorangular-meteor

Meteor publication error detection


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')'


Solution

  • 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));