Now I use this code to save error log from user to database
window.onerror = function (msg, url, line) {
$.ajax({
type: "POST",
url: "call/savelog.php",
data: {
type : "bug\n" + version,
message : 'Error message: '+msg+'\nURL: '+url+'\nLine Number: '+line
}
});
return true;
};
when error occur on jquery or kineticjs function
if it was in javascript console I will got something like this
Uncaught TypeError: Cannot read property '_id' of undefined kinetic-v4.0.2.js:1386
Kinetic.Node.remove kinetic-v4.0.2.js:1386
Kinetic.Layer.remove kinetic-v4.0.2.js:3667
drawCountdown side_play.js:105
so I’ll know error cause by my drawCountdown function in my javascript file side_play.js
but it appear like this in my error log
Error message: Uncaught TypeError: Cannot read property '_id' of undefined
URL: https://myurl.com/js/kinetic-v4.0.2.js
Line Number: 1386
so I don’t know which function that cause the error.
how to track down to the deepest function that cause error and save error log to database
You can wrap your functions in try/catch statements and if an error occurs you can catch errors and then write them in file via server for example.