【问题标题】: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');
}
},
});