Identify Errors
Add useful error logging and identify the root cause from your server logs.
Updated Jul 11, 2026
Before you start
- Understand the code you are hosting.
- Use a text editor or IDE (recommended) to update your files.
Add error logging
Server logs show why an application stops or behaves unexpectedly. Add logging to your main entry file before your application starts.
Logging an uncaught exception does not make the application safe to continue. Fix the root cause, then restart the server.
Node.js exceptions and promise rejections
// Logs synchronous runtime errors that reach the event loop.
process.on("uncaughtException", (error, origin) => {
console.error(`[CRITICAL ERROR] Uncaught Exception at: ${origin}`);
console.error(error.stack || error);
});
// Logs promise rejections that have no error handler.
process.on("unhandledRejection", (reason, promise) => {
console.error("[CRITICAL ERROR] Unhandled Promise Rejection:", promise);
console.error("Reason:", reason?.stack || reason);
});
Discord.js REST event logging
Use REST events to log specific response codes and take action based on them.
client.rest.on(RESTEvents.Response, (Req, Resp) => {
if (!(Resp.status === 429)) return;
console.log('[429] Rate limited!')
});
Identify the cause
- Restart the server and reproduce the problem.
- Review the first error in the console output.
- Trace the stack back to your code or configuration.
The final error can be a symptom. Earlier log entries often show the root cause.