errorhandler

Heyo peeps!

I was wondering if anyone had tried creating an error handler that would catch every type of error and log it somewhere, as right now i have alot of TryCatch functions which simple make the code look ugly.

Eaxmple of what i mean that might have a better way of doing so:
const fs = require('fs');

module.exports = (client) => {
    client.handleErrors = (error) => {
        console.error(error);

        fs.appendFile('error.log', `${new Date().toISOString()} - ${error}\n`, (err) => {
            if (err) throw err;
        });
    }
}

(keep in mind that this code still requires me to use TryCatch)
image.png
Was this page helpful?