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