mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-22 15:37:21 +00:00
🎨 Update error handling decorator
This commit is contained in:
parent
a3f3091702
commit
71f53017b7
@ -15,6 +15,9 @@ from utils.log import logger
|
|||||||
|
|
||||||
|
|
||||||
async def send_user_notification(update: Update, context: CallbackContext, text: str):
|
async def send_user_notification(update: Update, context: CallbackContext, text: str):
|
||||||
|
if not isinstance(update, Update):
|
||||||
|
logger.warning("错误的消息类型 %s", repr(update))
|
||||||
|
return
|
||||||
if update.inline_query is not None: # 忽略 inline_query
|
if update.inline_query is not None: # 忽略 inline_query
|
||||||
return
|
return
|
||||||
if "重新绑定" in text:
|
if "重新绑定" in text:
|
||||||
@ -52,7 +55,7 @@ def telegram_warning(update: Update, text: str):
|
|||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
chat = update.effective_chat
|
chat = update.effective_chat
|
||||||
msg = f"{text}\n" f"user_id[{user.id}] chat_id[{chat.id}] message_id[{message.id}] "
|
msg = f"{text}\n user_id[{user.id}] chat_id[{chat.id}] message_id[{message.id}]"
|
||||||
logger.warning(msg)
|
logger.warning(msg)
|
||||||
|
|
||||||
|
|
||||||
@ -101,7 +104,7 @@ def error_callable(func: Callable) -> Callable:
|
|||||||
else:
|
else:
|
||||||
logger.warning("Cookie错误")
|
logger.warning("Cookie错误")
|
||||||
logger.exception(exc)
|
logger.exception(exc)
|
||||||
await send_user_notification(update, context, f"出错了呜呜呜 ~ Cookie 无效 错误信息为 {exc.msg} 请尝试重新绑定")
|
await send_user_notification(update, context, f"出错了呜呜呜 ~ Cookie 无效 错误信息为 {exc.original} 请尝试重新绑定")
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
except TooManyRequests as exc:
|
except TooManyRequests as exc:
|
||||||
logger.warning("查询次数太多(操作频繁) %s", exc)
|
logger.warning("查询次数太多(操作频繁) %s", exc)
|
||||||
@ -125,7 +128,7 @@ def error_callable(func: Callable) -> Callable:
|
|||||||
logger.error("GenshinException")
|
logger.error("GenshinException")
|
||||||
logger.exception(exc)
|
logger.exception(exc)
|
||||||
await send_user_notification(
|
await send_user_notification(
|
||||||
update, context, f"出错了呜呜呜 ~ 获取账号信息发生错误 错误信息为 {exc.msg if exc.msg else exc.retcode} ~ 请稍后再试"
|
update, context, f"出错了呜呜呜 ~ 获取账号信息发生错误 错误信息为 {exc.original if exc.original else exc.retcode} ~ 请稍后再试"
|
||||||
)
|
)
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
except ReturnCodeError as exc:
|
except ReturnCodeError as exc:
|
||||||
|
Loading…
Reference in New Issue
Block a user