From 44978c8b7f36a6a335b642cd0998779e742866d2 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Sat, 23 Aug 2025 18:31:01 +0300 Subject: [PATCH] feat: add global error handling for the bot to log unhandled rejections and exceptions; improve error logging for Grammy bot errors --- apps/bot/src/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/bot/src/index.ts b/apps/bot/src/index.ts index 5e03ed6..94a5335 100644 --- a/apps/bot/src/index.ts +++ b/apps/bot/src/index.ts @@ -9,6 +9,12 @@ const bot = createBot({ token: environment.BOT_TOKEN, }); +bot.catch((error) => { + logger.error('Grammy bot error:'); + logger.error(`Message: ${error?.message}`); + logger.error(error.error); // собственно, ошибка +}); + const runner = run(bot); const redis = getRedisInstance(); @@ -36,4 +42,12 @@ async function gracefulShutdown(signal: string) { process.once('SIGINT', () => gracefulShutdown('SIGINT')); process.once('SIGTERM', () => gracefulShutdown('SIGTERM')); +process.on('unhandledRejection', (reason) => { + logger.error('Unhandled Rejection: ' + reason); +}); + +process.on('uncaughtException', (error) => { + logger.error('Uncaught Exception: ' + error); +}); + logger.info('Bot started');