Reputation: 778
What is the ember.js community recommendation for reporting Ember app crashes? I'm looking for the equivalent of the exception_notifier gem in Rails so that I can be notified if users are experiencing errors.
This Stack Overflow post recommends generic javascript error handling solutions including:
window.onerror
yourselfwindow.onerror
for you like Airbrake.io or MusculaI'm hoping there is some kind of Mixin that gives you all this error handling code, and provides richer error messages (such as the current route when the error occurred, etc). Does this exist yet? If not, what are people doing to solve this problem?
Upvotes: 5
Views: 1424
Reputation: 3309
Any error reporting like the Rails gem is going to depend on some sort of server backend to handle the error, such as emailing admins, etc. It makes sense that Rails would have a whole gem dedicated to this sort of thing, since Rails is going to have the whole stack trace, session, and all sorts of other variables that are convenient(/necessary) to have for debugging the issue, but for front-end apps (e.g. Ember), all the error information is on the client side, so all the backend logic would do is expose an API that your Ember app can talk to which would forward whatever information you send to it from the app and send it to your email, or whatever you want to do with it.
To do this in Ember, you can specify the Ember.onerror
function:
Ember.onerror = function(error) {
caught = error;
Em.$.ajax('/report-error', 'POST', {
stack: error.stack,
otherInformation: 'whatever app state you want to provide'
});
};
This receives the JavaScript Error
object that was thrown, which may or may not have the non-standard stack
property that contains the stack trace which you could send to the server among any other App-specific state you'd want to send, though you'd probably want to keep it simple so that you don't cause other errors and end up in a crazy error loop from hell.
Upvotes: 5