Last active
January 25, 2020 13:32
-
-
Save aliaksandr-master/70623b300119b4c970d56b6b34f2b97f to your computer and use it in GitHub Desktop.
error notificator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onErrorNotice = function (func) { | |
'use strict'; | |
var onerror = function(e) { | |
func({ | |
title: e.title || 'JavaScript error', | |
message: e.error && e.error.name && 'number' in e.error ? e.error.name + ': ' + e.message : e.message, | |
file: (e.filename && e.filename.search(/^https?:|file:/) !== -1 ? e.filename + ':::' : '') + (e.filename ? e.filename + ':' + (e.lineno == null ? '' : e.lineno) + ':' + (e.colno == null ? '' : e.colno) : ''), | |
stack: (e.error && e.error.stack) || e.stack || '' | |
}); | |
}; | |
if (window.addEventListener) { | |
window.addEventListener('error', onerror, false); | |
} else { | |
var oldOnError = window.onerror; | |
window.onerror = function(message, filename, lineno, colno, error) { | |
onerror({ | |
message: message, | |
filename: filename, | |
lineno: lineno, | |
colno: colno, | |
error: error | |
}); | |
if (typeof oldOnError === 'function') { | |
oldOnError.apply(window, arguments); | |
} | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment