javascript - Meteor发布错误检测

标签 javascript angular meteor angular-meteor

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

最佳答案

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

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

关于javascript - Meteor发布错误检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42850420/

相关文章:

javascript - 表单组验证不适用于自定义创建的组件

javascript - 在 Angular2 上使用正则表达式制作管道

meteor - 如何使用 blaze-layout 渲染将数据传递到模板?

javascript - 调用服务器端方法时 Meteor 中的错误处理

javascript - 如果鼠标聚焦在新的 div 上,我如何在鼠标悬停事件期间显示持续存在的 div?

javascript - 通过 "value="提交“类型 ="button"的火灾事件 - Javascript

JavaScript、HTML 和 IndexedDB

html - 是否可以在有 Angular 形式内放置粘性 div?

javascript - 模拟调用 'deals.insert'错误效果时出现异常

javascript - 循环图像数组并将它们作为背景图像应用到 div