vendredi 17 mai 2019

How to fix Sentry User Feedback Error - Cannot read property 'showReportDialog' of undefined

I've been trying to get a User Feedback dialog to show when I click on a certain button, but I've had some trouble. I successfully got it to work when I make a call my API and end up getting an error shown first.

However I created a button that would trigger a call to Sentry.showReportDialog, but I get a 'Cannot read property 'showReportDialog' of undefined' error. I've tried using Sentry.capture Message/Exception/Error to generate an eventId, but I still got the same error. This is my current code that's failing, but I've modified it a decent amount and was still getting the same undefined error for showReportDialog, even when I tried the method that worked with my API call. This web application is running using Ember.js v3.5.1 and in my package.json the dependency for sentry is "@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 });
}




Aucun commentaire:

Enregistrer un commentaire