Salz0 / telegram_flea

A open-source flea market bot, to be used in any Community
MIT License
9 stars 21 forks source link

Handle exception, when caption too long #59

Open Salz0 opened 9 months ago

Salz0 commented 9 months ago

The user should be notified that this length has a constraint, let it be around 2k symbols

Looks something like this:

2023-11-06T13:06:08.294794+00:00 app[bot.1]:   File "/app/.heroku/python/lib/python3.11/site-packages/aiogram/bot/base.py", line 236, in request
2023-11-06T13:06:08.294794+00:00 app[bot.1]:     return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
2023-11-06T13:06:08.294794+00:00 app[bot.1]:                  │   │                  │    │              │    │       │             │       │     └ {'photo': <InputFile 'attach://Zr7EVo7IeESjfXai5uPjYQ' with file='<_io.BufferedReader name='item_photo.jpg'>'>}
2023-11-06T13:06:08.294795+00:00 app[bot.1]:                  │   │                  │    │              │    │       │             │       └ {'chat_id': , 'caption': 'Текстові картинки з символів, які також називають ASCII арт це одне з мистецтв доступних к...
2023-11-06T13:06:08.294796+00:00 app[bot.1]:                  │   │                  │    │              │    │       │             └ 'sendPhoto'
2023-11-06T13:06:08.294796+00:00 app[bot.1]:                  │   │                  │    │              │    │       └ <aiogram.bot.bot.Bot object at 0x7fab07b39910>
2023-11-06T13:06:08.294796+00:00 app[bot.1]:                  │   │                  │    │              │    └ TelegramAPIServer(base='https://api.telegram.org/bot{token}/{method}', file='https://api.telegram.org/file/bot{token}/{path}')
2023-11-06T13:06:08.294796+00:00 app[bot.1]:                  │   │                  │    │              └ <aiogram.bot.bot.Bot object at 0x7fab07b39910>
2023-11-06T13:06:08.294796+00:00 app[bot.1]:                  │   │                  │    └ <function BaseBot.get_session at 0x7fab07f20360>
2023-11-06T13:06:08.294796+00:00 app[bot.1]:                  │   │                  └ <aiogram.bot.bot.Bot object at 0x7fab07b39910>
2023-11-06T13:06:08.294797+00:00 app[bot.1]:                  │   └ <function make_request at 0x7fab07ea3c40>
2023-11-06T13:06:08.294797+00:00 app[bot.1]:                  └ <module 'aiogram.bot.api' from '/app/.heroku/python/lib/python3.11/site-packages/aiogram/bot/api.py'>
2023-11-06T13:06:08.294797+00:00 app[bot.1]:   File "/app/.heroku/python/lib/python3.11/site-packages/aiogram/bot/api.py", line 140, in make_request
2023-11-06T13:06:08.294797+00:00 app[bot.1]:     return check_result(method, response.content_type, response.status, await response.text())
2023-11-06T13:06:08.294797+00:00 app[bot.1]:            │            │       │        │             │        │             │        └ <function ClientResponse.text at 0x7fab08381620>
2023-11-06T13:06:08.294800+00:00 app[bot.1]:            │            │       │        │             │        │             └ <ClientResponse(https://api.telegram.org/bot6738102641:AAG9NTvl5IFG1qTBDmBe7vlAHteaUFhc-zA/sendPhoto) [400 Bad Request]>
2023-11-06T13:06:08.294800+00:00 app[bot.1]:            │            │       │        │             │        │               <CIM...
2023-11-06T13:06:08.294800+00:00 app[bot.1]:            │            │       │        │             │        └ 400
2023-11-06T13:06:08.294800+00:00 app[bot.1]:            │            │       │        │             └ <ClientResponse(https://api.telegram.org/bot6738102641:AAG9NTvl5IFG1qTBDmBe7vlAHteaUFhc-zA/sendPhoto) [400 Bad Request]>
2023-11-06T13:06:08.294800+00:00 app[bot.1]:            │            │       │        │               <CIM...
2023-11-06T13:06:08.294801+00:00 app[bot.1]:            │            │       │        └ <property object at 0x7fab0854d850>
2023-11-06T13:06:08.294802+00:00 app[bot.1]:            │            │       └ <ClientResponse(https://api.telegram.org/bot6738102641:AAG9NTvl5IFG1qTBDmBe7vlAHteaUFhc-zA/sendPhoto) [400 Bad Request]>
2023-11-06T13:06:08.294802+00:00 app[bot.1]:            │            │         <CIM...
2023-11-06T13:06:08.294802+00:00 app[bot.1]:            │            └ 'sendPhoto'
2023-11-06T13:06:08.294802+00:00 app[bot.1]:            └ <function check_result at 0x7fab07ea3d80>
2023-11-06T13:06:08.294802+00:00 app[bot.1]:   File "/app/.heroku/python/lib/python3.11/site-packages/aiogram/bot/api.py", line 115, in check_result
2023-11-06T13:06:08.294803+00:00 app[bot.1]:     exceptions.BadRequest.detect(description)
2023-11-06T13:06:08.294803+00:00 app[bot.1]:     │          │          │      └ 'Bad Request: message caption is too long'
2023-11-06T13:06:08.294803+00:00 app[bot.1]:     │          │          └ <classmethod(<function _MatchErrorMixin.detect at 0x7fab080c2de0>)>
2023-11-06T13:06:08.294803+00:00 app[bot.1]:     │          └ <class 'aiogram.utils.exceptions.BadRequest'>
2023-11-06T13:06:08.294803+00:00 app[bot.1]:     └ <module 'aiogram.utils.exceptions' from '/app/.heroku/python/lib/python3.11/site-packages/aiogram/utils/exceptions.py'>
2023-11-06T13:06:08.294804+00:00 app[bot.1]:   File "/app/.heroku/python/lib/python3.11/site-packages/aiogram/utils/exceptions.py", line 141, in detect
2023-11-06T13:06:08.294804+00:00 app[bot.1]:     raise cls(description)
2023-11-06T13:06:08.294804+00:00 app[bot.1]:           │   └ 'bad request: message caption is too long'
2023-11-06T13:06:08.294804+00:00 app[bot.1]:           └ <class 'aiogram.utils.exceptions.BadRequest'>