This document discusses the importance of logging JavaScript errors to understand issues that users encounter on a website. It provides an overview of challenges in logging errors, such as localized error messages and cryptic messages. It then describes different approaches to logging errors, such as using window.onerror, try/catch blocks, and sending logs via image requests, iframes, or XHR requests. Finally, it demonstrates setting up a dashboard to visualize errors using Node.js, Express, and Redis.
17. LOCALIZED MESSAGES
Expected identifier, string or number
Identificador esperado
Se esperaba un identificador, una cadena o un número
Bezeichner erwartet
标识
ّف د و ا
23. WINDOW.ONERROR
works across the board
amount of information is limited
window.onerror = function(msg, url, lno){
/*
No impact besides parsing
overhead is only for the request to log the error
when one actually happens
*/
return true; //hides the message in supported browsers
};
24. TRY/CATCH
works across the board
try {
throw new Error("my error");
} catch (e){
e.stack; //chrome, firefox
e.message; //opera
log(e.stack || e.message || e);
}
25. TRY/CATCH
more meaningful errors
performance hit, but you should evaluate if it matters
may lead to a lot of nesting if not thought through
var fn = function(){
throw "new error"; //this exception will not be caught
//since it's a string it will not have stack trace
};
try{
setTimeout(fn,0);
} catch(e) { }