【发布时间】: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 });
}
【问题讨论】: