Javascript error reporting

It’s all very well to be capturing all the errors that happen server side, logging them to a database and reporting on them like any robust web service ought to, what about the client?

So today I added reporting for client-side errors to the project I’m working on. Turned out to be remarkably easy. A couple of lines of JQuery code are all that’s needed on the client to capture the error and report it back to a web service:-

window.onerror = errorHandler; // Report javascript errors back to web site function errorHandler(msg,url, lno) { try { jQuery.ajax({ type: "POST", url: '/services/error/clientError.ashx', processData: true, contentType: "application/text", timeout: 10000, dataType: "json", data: { msg: msg, url: url, lno: lno }, success: function(responseData) {}, error: function() {}, complete: function() {} }); } catch (err) { // do nothing } } 

And on the server side the clientError.ashx can just grab the body of the post, split it back up and report on the error into the normal server side database of all exceptions.

In under an hour I added reporting for all client side errors and armed with that we’ll be able to find and fix those annoying browser (IE?) issues some of our customers see from time to time.



Mon Apr 20 2009 21:08:00 GMT-0700 (Pacific Daylight Time)



Disqus goes here