如何解决Sentry用户反馈错误-无法读取未定义的属性'showReportDialog'

时间:2019-05-17 23:42:40

标签: ember.js sentry

当我单击某个按钮时,我一直试图显示一个“用户反馈”对话框,但是遇到了一些麻烦。调用我的API时,我成功地使它起作用,并最终导致首先显示错误。

但是,我创建了一个按钮,该按钮将触发对Sentry.showReportDialog的调用,但是出现“无法读取属性'showReportDialog'的状态未定义”错误。我试过使用Sentry.capture消息/异常/错误来生成eventId,但是我仍然遇到相同的错误。这是我当前的失败代码,但是即使我尝试了与API调用一起使用的方法,我也对其进行了相当大的修改,并且仍对showReportDialog遇到相同的未定义错误。此Web应用程序正在使用Ember.js v3.5.1运行,在我的package.json中,哨兵的依赖性为 “ @ sentry / browser”:“ ^ 4.5.3”

// works
try {
    $('.ember-application').addClass('request-loading');
    this.model.setProperties(properties);
    return yield this.model.save();
} catch (err) {
    // Get feedback from user through sentry
    Sentry.init({
        dsn:'https://ec08003a76fa4b6e8f111237ed3ed8e1@sentry.io/1369772',
        beforeSend(event) {
            if (event.exception) {
            Sentry.showReportDialog({ eventId: event.event_id });
        }
        return event;
    },
});

}

// does not work
try {
    throw new Error();
} catch (e) {
    var eventId = yield Sentry.captureException(e, function(sendErr, eventId) {
        // This callback fires once the report has been sent to Sentry
        if (sendErr) {
            console.error('Failed to send captured exception to Sentry');
        } else {
            console.log('Captured exception and send to Sentry successfully');
            console.log(eventId);
        }
    });
    console.log(eventId);
    Sentry.showReportDialog({ eventId: eventId });
}

1 个答案:

答案 0 :(得分:1)

以下代码最终对我有用

try {
        throw new Error();
    } catch (e) {
        Sentry.init({
            dsn: 'https://ec080033425613e7ed3ed8e1@sentry.io/1369772',
            beforeSend(event) {
                return event;
            },
        });
        var eventId = yield Sentry.captureException(e, function() {});
        Sentry.showReportDialog({
            eventId: eventId,
    });
}