I would like to ask is there a way to globally catch all the errors regarding requests/responses that Telegram sends? I have multiple scenes with many answers and dialogue decisions and I can't really think of a better way of catching all the errors than doing it globally. I tried doing this:
process.on("uncaughtException", (err) => {
console.log(err);
});
process.on("unhandledRejection", (err) => {
console.log(err);
});
bot.catch((err, ctx) => {
console.log(err, ctx);
});
But it doesn't seem to work properly, there is a certain type of request/response that I can't catch. This is the error for it:
Unhandled error while processing {
update_id: <id>,
my_chat_member: {
chat: {
id: <id>,
first_name: '<name>',
username: '<name>',
type: 'private'
},
from: {
id: <id>,
is_bot: false,
first_name: '<name>',
username: '<name>',
language_code: 'en'
},
date: 1670331646,
old_chat_member: { user: [Object], status: 'member' },
new_chat_member: { user: [Object], status: 'kicked', until_date: 0 }
}
}
TelegramError: 403: Forbidden: bot was blocked by the user
at Telegram.callApi (/<path>/node_modules/telegraf/lib/core/network/client.js:291:19)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async execute (/<path>/node_modules/telegraf/lib/composer.js:471:17)
at async /<path>/node_modules/telegraf/lib/composer.js:472:21
at async execute (/<path>/node_modules/telegraf/lib/composer.js:471:17)
at async /<path>/node_modules/telegraf/lib/composer.js:472:21
at async execute (/<path>/node_modules/telegraf/lib/composer.js:471:17)
at async execute (/<path>/node_modules/telegraf/lib/composer.js:471:17)
at async /<path>/node_modules/telegraf/lib/composer.js:472:21 {
response: {
ok: false,
error_code: 403,
description: 'Forbidden: bot was blocked by the user'
},
on: {
method: 'sendMessage',
payload: { chat_id: <id>, text: 'Choose an option' }
}
}
All the other errors are caught just fine. Also I dont know where old_chat_member
and new_chat_member
comes from - bot can't be used in the groups so it shouldn't appear.