improve error handling and logging

This commit is contained in:
Ruben van de Ven 2020-09-28 11:21:00 +02:00
parent a3c41c785d
commit aa2d324cab

View file

@ -425,8 +425,8 @@ window.onerror = function (msg, url, lineNumber, columnNo, error) {
// var fileInfo = getScriptOff(errorNum);
// data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
// } else {
var fileInfo = getScriptOff(lineNumber);
data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
// var fileInfo = getScriptOff(lineNumber);
data = msg + ' (' + error.fileName + ': line ' + error.lineNumber + ')';
// }
window.parent.postMessage([{
log: [{
@ -434,23 +434,23 @@ window.onerror = function (msg, url, lineNumber, columnNo, error) {
data: [data],
id: Date.now().toString()
}],
source: fileInfo[1]
source: error.fileName
}], '*');
return false;
};
// catch rejected promises
window.onunhandledrejection = function (event) {
if (event.reason && event.reason.message && event.reason.stack){
var errorNum = event.reason.stack.split('about:srcdoc:')[1].split(':')[0];
var fileInfo = getScriptOff(errorNum);
var data = event.reason.message + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
// var errorNum = event.reason.stack.split('about:srcdoc:')[1].split(':')[0];
// var fileInfo = getScriptOff(errorNum);
var data = event.reason.message + ' (' + event.reason.stack + ': line ' + event.reason.stack.split("\n")[0] + ')';
window.parent.postMessage([{
log: [{
method: 'error',
data: [data],
id: Date.now().toString()
}],
source: fileInfo[1]
source: event.reason.stack.split("\n")[0]
}], '*');
}
};