【问题标题】:Override Meteor's exception handling覆盖 Meteor 的异常处理
【发布时间】:2016-12-08 11:22:11
【问题描述】:

我正在尝试将 sentry.io 与 Meteor 一起使用。然而 Meteor 似乎吞下了所有的错误,所以即使手动抛出异常也不会被这段代码拾取。

process.on('uncaughtException', (err) => {
  console.log('exception')
  console.log(err)
});

有什么方法可以将全局错误处理程序添加到 Meteor 而不是它自己的内部错误处理程序,以便我可以将其链接到自定义错误处理代码?

【问题讨论】:

    标签: javascript meteor sentry


    【解决方案1】:

    您总是有机会在 Meteor 中捕获错误(例如在 Meteor 方法中)并自己处理。例如:

    Meteor.methods({
      someMethod() {
        try {
          const result = callToSentryFunc();
    
          return result;
        } catch (e) {
          // e === an error object generated by sentry
          throw new Meteor.Error('your-own-error-code',
            'You can throw your own error that gets sent back to the client');
        }
      },
    });
    

    【讨论】:

      猜你喜欢
      • 2018-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 2020-01-23
      • 1970-01-01
      • 2020-09-22
      • 2018-12-15
      相关资源
      最近更新 更多