2017-03-17 6 views
1

WebアプリケーションでMeteorとangularJS 2を使用しています。以下の公開機能をご覧ください。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(); 
}); 

は今angularjs2から上記の出版物を購読している間、私は次のコードを使用しています: -

//ヴァール宣言

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メソッドの2番目の引数はエラーコールバックです。ここでいくつかの条件を記述できます。

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