Node.js Sentry错误捕获不起作用

时间:2018-09-26 14:28:01

标签: node.js sentry

在Node.js 8中,如果我在代码末尾使用process.exit(0),则无法捕获哨兵错误。否则工作正常

const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'https://c3f5****************34dbf@sentry.io/1288850' });
try{
    throw new Error('test-error');
}
catch(e){
    const Eid = Sentry.captureException(e);
    console.log(Eid);
}
process.exit(0);

1 个答案:

答案 0 :(得分:0)

Sentry.captureException(e)是异步的,因此process.exit(0)在Sentry.captureException能够运行之前终止了该进程。