Is there a technique for reporting Javascript errors?

Asked

Viewed 59 times

4

The following is as follows: I use the Laravel Framework and, in it, configure the application so that when any server error occurs, it sends me an email, writes in a log file and/or sends me a message in Telegram.

This in a way helps me anticipate a problem before a customer complains that the system is malfunctioning.

In this case, sometimes, due to incorrect posting 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 medium, or some standard of error communication that could be applied in the case of Javascript?

For example, if a customer, when accessing the page, has a problem with the jQuery because its internet is blocking the CDN (content delivery network) of the same, this generates an error in the console.

Is there any technique or standard to report these errors, or save them in a log, as is usually done in server-side applications ?

1 answer

2

Look, I don’t think it’s a good idea to keep all the Javascript errors. Javascript errors occur for several reasons, they can occur even by connection latency. But if you really want to record all the errors, I suggest you overwrite the method console.error() which is usually called when an error is launched.

//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);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.