I am in the design process of a fairly robust rich client application which I tend to base the client code on Backbone, and I am curious as to the available/recommended error reporting implementation.
Due to our dependency on fat client-ish code, we want to know as much as we can about javascript error occurring.
Ideas?
I would suggest making your main App
namespace object extend Backbone.events
and listen for "error" events and report the details accordingly. This will be a nice central place to aggregate all errors and report them uniformly. You could combine various techniques for actually logging the error including displaying a notice to the user, adding some details to a hidden node in the DOM for tech support, or sending details to a remote service on the web.
Then throughout your code base you will need to actually detect/catch the errors (which usually means explicitly coding to check for them in JavaScript), gather the relevant information (perhaps a decent stack trace), and fire an "error" event into the App
event bus. This could be errors such as DOM selectors missing that should be there when rendering a view, unexpected data received from the server, etc.
For errors with AJAX/HTTP requests, you can override Backbone.sync
and add an additional error reporting there. That is a nice central place where all your interactions with the server will happen. Follow the same pattern of detect the error, gather details, fire an "error" event into the main App
event bus, then either allow the application to continue if possible or degrade/fail gracefully if the error is unrecoverable.