2.1.26 check_post_request_and_get_data

This commit is contained in:
SDE
2025-01-18 13:55:49 +03:00
parent 2a7a666f7d
commit 2f0e1bb396
3 changed files with 103 additions and 23 deletions

49
BaseModels/exceptions.py Normal file
View File

@@ -0,0 +1,49 @@
import asyncio
import traceback
from asgiref.sync import sync_to_async
from BaseModels.mailSender import techSendMail
from BaseModels.print_funcs import print_ext
from GeneralApp.funcs_options import get_mail_send_options
# from MessageBotsApp.telegram.tg_bot import send_message
async def send_exception_msg(msgr_msg, mail_msg):
# from MessageBotsApp.funcs import send_msg_to_staff
mail_sets = await sync_to_async(get_mail_send_options)()
# await send_msg_to_staff('telegram', msgr_msg)
await sync_to_async(techSendMail)(sets=mail_sets, html_content=mail_msg, title='iBaked Exception')
return True
async def exception_processing(exc, user=None):
tb = traceback.format_exc()
cutted_tb = tb[:500]
msgr_msg = f'user {str(user)} Exception = {str(exc)}\n{str(cutted_tb)}'
mail_msg = f'user {str(user)} Exception = {str(exc)}<br>\n{str(tb)}'
print_ext(msgr_msg)
# try:
# loop = asyncio.get_event_loop()
# except RuntimeError:
# loop = asyncio.new_event_loop()
# asyncio.set_event_loop(loop)
#
# loop = asyncio.new_event_loop()
# asyncio.set_event_loop(loop)
# async_result = loop.run_until_complete(send_exception_msg(msgr_msg, mail_msg))
# loop.close()
loop = asyncio.get_event_loop()
task = loop.create_task(send_exception_msg(msgr_msg, mail_msg))
status_code = 400
return msgr_msg, status_code