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;
});
}
}
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)
1 Reply
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers.
Want results from more Discord servers?
Add your server