$("html").ajaxError(function (event, jqXHR, ajaxSettings, thrownError){
//show proper message based on error.
});
I’m also sending JavaScript errors to server using $.ajax() from catch block and from window.onerror function. In case those two calls fail, I don’t want it to come to above ajaxError handler.
The first error handler will catch all exceptions thrown by jQuery’s ajax functions. If you don’t want it to handle an exception, I would suggest inspecting the URL of the ajax request to see if it is to your JS Error handling script, and if so, ignore it.