Is there a technique for reporting Javascript errors?

4
It is the following: I use the Laravel Framework and, in it, I configure the application so that when a server error happens, it sends me an email, writes to a log file and / or sends me a message in the Telegram.

This kind of helps me anticipate a problem before a customer complains that the system is giving error.

In case, sometimes because of wrong publication or old cache, when updating an application, some errors may appear in the Javascript console and, because of this, some functionality of an application is impaired.

I would like to know if there is any technique, a means, or some standard of error communication that could be applied in the case of Javascript?

For example, if a client, when accessing the page, has a problem with jQuery because their internet is blocking the content delivery network (CDN), it causes an error in the console.

Is there a technique or a standard for reporting these errors, or saving them in a log, as you usually do in server-side applications?

    
asked by anonymous 26.10.2018 / 18:27

1 answer

2

Look, I do not think it's a good idea to save all JavaScript errors. JavaScript errors occur for a variety of reasons, and can occur even through latency on the connection. But if you really want to log all errors, I suggest you override the console.error() method that is usually called when an error is thrown.

//Armazeno o método console.error em uma variável para não perde-lo
const consoleError = console.error;

//Sobrescrevo o método console.error
console.error = function(...er) {

    //Chamo uma função AJAX para registrar o erro
    $.post("error.php", {error: er[0].toString()});

    //Chamo o método console.error padrão que foi armazenado em consoleError
    consoleError(...er);
}
    
27.10.2018 / 01:33