【问题标题】:Meteor publication error detection流星发布错误检测
【发布时间】:2017-08-08 14:12:30
【问题描述】:

我在 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.
});

问题就在这里,我怎么能捕捉到发布功能错误

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

【问题讨论】:

    标签: javascript angular meteor angular-meteor


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 好的,谢谢。但我怎样才能跟踪错误?我已阅读有关 onReady 和 onStop 功能的信息。当我在 subscribe() 中调用任何函数时,onReady 调用成功。
      • 我的回答有用吗?问题在出版物中,所以在抛出错误之前添加console.log(this.userId)
      • 否,发布功能没有问题。假设是否有任何错误被捕获,我想抛出那个错误。不是我如何在订阅功能中捕获客户端的错误。
      • 对不起,我误解了这个问题,这里有一个更新。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      • 2014-05-04
      • 1970-01-01
      • 2017-10-02
      • 2017-05-12
      • 1970-01-01
      相关资源
      最近更新 更多