feat: implement global error handling for Discord.js interactions and promise rejections
This commit is contained in:
@@ -5,6 +5,50 @@ import logger from "../core/lib/logger";
|
|||||||
bot.on(Events.ClientReady, () => {
|
bot.on(Events.ClientReady, () => {
|
||||||
logger.info("Ready!");
|
logger.info("Ready!");
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// 🛡️ HANDLER GLOBAL PARA ERRORES DE DISCORD.JS
|
||||||
|
// ============================================
|
||||||
|
// Interceptar errores específicos de ModalSubmitInteraction con UserSelect
|
||||||
|
|
||||||
|
process.on('uncaughtException', (error) => {
|
||||||
|
// Interceptar errores específicos de Discord.js GuildMemberManager
|
||||||
|
if (error.message?.includes("Cannot read properties of undefined (reading 'id')") &&
|
||||||
|
error.stack?.includes('GuildMemberManager._add')) {
|
||||||
|
|
||||||
|
logger.warn('🔧 Discord.js bug interceptado: GuildMemberManager error con UserSelect en modal');
|
||||||
|
// @ts-ignore
|
||||||
|
logger.warn('Stack trace:', error.stack);
|
||||||
|
|
||||||
|
// NO terminar el proceso, solo logear el error
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Para otros errores críticos, mantener el comportamiento original
|
||||||
|
// @ts-ignore
|
||||||
|
logger.error('💥 UncaughtException crítico:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('unhandledRejection', (reason, promise) => {
|
||||||
|
// Interceptar rechazos relacionados con el mismo bug
|
||||||
|
if (reason && typeof reason === 'object' &&
|
||||||
|
'message' in reason &&
|
||||||
|
// @ts-ignore
|
||||||
|
reason.message?.includes("Cannot read properties of undefined (reading 'id')")) {
|
||||||
|
|
||||||
|
logger.warn('🔧 Discord.js promise rejection interceptada: GuildMemberManager error');
|
||||||
|
// @ts-ignore
|
||||||
|
logger.warn('Reason:', reason);
|
||||||
|
|
||||||
|
// NO terminar el proceso
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Para otras promesas rechazadas, logear pero continuar
|
||||||
|
// @ts-ignore
|
||||||
|
logger.error('🚨 UnhandledRejection:', reason);
|
||||||
|
});
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// 🚀 OPCIÓN 1: ACTIVIDAD FIJA (RECOMENDADO PARA HEROKU 512MB)
|
// 🚀 OPCIÓN 1: ACTIVIDAD FIJA (RECOMENDADO PARA HEROKU 512MB)
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|||||||
Reference in New Issue
Block a user