2 * Try to catch errors in modules which don't do their own error handling.
4 * @class mw.errorLogger
12 * Fired via mw.track when an error is not handled by local code and is caught by the
13 * window.onerror handler.
16 * @param {string} errorMessage Error errorMessage.
17 * @param {string} url URL where error was raised.
18 * @param {number} lineNumber Line number where error was raised.
19 * @param {number} [columnNumber] Line number where error was raised. Not all browsers
21 * @param {Error|Mixed} [errorObject] The error object. Typically an instance of Error, but anything
22 * (even a primitive value) passed to a throw clause will end up here.
26 * Install a window.onerror handler that will report via mw.track, while preserving
27 * any previous handler.
29 * @param {Object} window
31 installGlobalHandler: function ( window ) {
32 // We will preserve the return value of the previous handler. window.onerror works the
33 // opposite way than normal event handlers (returning true will prevent the default
34 // action, returning false will let the browser handle the error normally, by e.g.
35 // logging to the console), so our fallback old handler needs to return false.
36 var oldHandler = window.onerror || function () { return false; };
39 * Dumb window.onerror handler which forwards the errors via mw.track.
43 window.onerror = function ( errorMessage, url, lineNumber, columnNumber, errorObject ) {
44 mw.track( 'global.error', { errorMessage: errorMessage, url: url,
45 lineNumber: lineNumber, columnNumber: columnNumber, errorObject: errorObject } );
46 return oldHandler.apply( this, arguments );
51 mw.errorLogger.installGlobalHandler( window );