feat: add global error handling for the bot to log unhandled rejections and exceptions; improve error logging for Grammy bot errors
This commit is contained in:
parent
9f7412df6b
commit
44978c8b7f
@ -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');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user