| Total Complexity | 9 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | |||
| 3 | |||
| 4 | from utils.misc.tg_html import mention_html |
||
| 5 | from data.config import ADMINS |
||
| 6 | from loader import dp, bot |
||
| 7 | from aiogram import types |
||
| 8 | import traceback |
||
| 9 | import logging |
||
| 10 | import sys |
||
| 11 | |||
| 12 | |||
| 13 | """ |
||
| 14 | |||
| 15 | |||
| 16 | Created on 25.09.2021 |
||
| 17 | |||
| 18 | @author: Nikita |
||
| 19 | |||
| 20 | |||
| 21 | """ |
||
| 22 | |||
| 23 | |||
| 24 | @dp.errors_handler() |
||
| 25 | async def error(update: types.Update, exception): |
||
| 26 | |||
| 27 | """ |
||
| 28 | |||
| 29 | The function is designed for processing errors. |
||
| 30 | |||
| 31 | """ |
||
| 32 | |||
| 33 | if update.message or update.edited_message: |
||
| 34 | |||
| 35 | text = "К сожалению произошла ошибка в момент обработки сообщения... " \ |
||
| 36 | "Мы уже работаем над этой проблемой. 🤔" |
||
| 37 | |||
| 38 | await update.message.reply(text=text) |
||
| 39 | |||
| 40 | trace = "".join(traceback.format_tb(sys.exc_info()[2])) |
||
| 41 | payload = [] |
||
| 42 | |||
| 43 | if update.message.from_user: |
||
| 44 | |||
| 45 | bad_user = await mention_html(update.message.from_user.id, update.message.from_user.first_name) |
||
| 46 | payload.append(f' с пользователем {bad_user}') |
||
| 47 | |||
| 48 | if update.channel_post or update.edited_channel_post: |
||
| 49 | payload.append(f' внутри чата <i>{update.edited_channel_post}</i>') |
||
| 50 | |||
| 51 | if update.channel_post.from_user.username: |
||
| 52 | payload.append(f' (@{update.channel_post.from_user.username})') |
||
| 53 | |||
| 54 | if update.poll: |
||
| 55 | payload.append(f' с id опроса {update.poll.id}.') |
||
| 56 | |||
| 57 | text = f"Ошибка <code>{exception}</code> случилась{''.join(payload)}. " \ |
||
| 58 | f"Полная трассировка:\n\n<code>{trace}</code>" |
||
| 59 | |||
| 60 | for dev_id in ADMINS: |
||
| 61 | |||
| 62 | await bot.send_message(chat_id=dev_id, |
||
| 63 | text=text, |
||
| 64 | parse_mode=types.ParseMode.HTML) |
||
| 65 | |||
| 66 | logging.exception(f'Update: {update} \n{exception}') |
||
| 67 |