2017-03-17 3 views
1

웹 응용 프로그램에서 Meteor 및 angularJS 2를 사용하고 있습니다. 아래의 게시 기능을 살펴보십시오. angularjs2에서 상기 공보를 구독하면서 이제Meteor publication error detection

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(); 
}); 

, 나는 다음 코드를 사용하고 있습니다 : -

// 바르 선언

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

문제는 여기에 내가 어떻게 잡을 수 있다는 것입니다 게시 함수 오류

'throw new Meteor.Error (403,'UnAuthorized error ')'

답변

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 함수에 대해 읽었습니다. onReady는 subscribe() 내에서 functin을 호출했을 때 성공적으로 호출되었습니다. – Shubham

+0

내 대답이 효과가 있습니까? 문제가 출판물에 있으므로 오류를 던지기 전에'console.log (this.userId)'를 추가하십시오. – mutdmour

+0

아니요, 게시 기능에는 문제가 없습니다. 어떤 오류가 잡히고, 그 오류를 던지고 싶다고 가정합니다. 어떻게 구독 기능에서 클라이언트 쪽에서 오류를 잡을 수 있습니까? – Shubham