Files
tripwithbonus/BaseModels/exceptions.py

50 lines
1.4 KiB
Python

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