【问题标题】:How to fix Sentry User Feedback Error - Cannot read property 'showReportDialog' of undefined如何修复 Sentry 用户反馈错误 - 无法读取未定义的属性“showReportDialog”
【发布时间】:2019-05-17 23:42:40
【问题描述】:

我一直在尝试在单击某个按钮时显示用户反馈对话框,但遇到了一些问题。当我调用我的 API 并最终首先显示错误时,我成功地让它工作了。

但是,我创建了一个会触发对 Sentry.showReportDialog 的调用的按钮,但我收到“无法读取未定义的属性 'showReportDialog'”错误。我尝试使用 Sentry.capture Message/Exception/Error 来生成 eventId,但我仍然遇到同样的错误。这是我当前失败的代码,但我已经对其进行了相当多的修改,并且即使我尝试了与我的 API 调用一起使用的方法,仍然收到相同的未定义错误 showReportDialog。此 Web 应用程序使用 Ember.js v3.5.1 运行,在我的 package.json 中,sentry 的依赖项是 "@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 });
}

【问题讨论】:

    标签: ember.js sentry


    【解决方案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,
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 2020-01-20
      • 2019-02-10
      • 2022-01-06
      • 2019-12-08
      • 2019-10-19
      • 2019-08-29
      • 1970-01-01
      • 2020-06-16
      相关资源
      最近更新 更多