Skip to content

Instantly share code, notes, and snippets.

@aliaksandr-master
Last active January 25, 2020 13:32
Show Gist options
  • Save aliaksandr-master/70623b300119b4c970d56b6b34f2b97f to your computer and use it in GitHub Desktop.
Save aliaksandr-master/70623b300119b4c970d56b6b34f2b97f to your computer and use it in GitHub Desktop.
error notificator
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