🎨 Update error handling decorator

This commit is contained in:
洛水居室 2022-11-19 16:43:50 +08:00
parent a3f3091702
commit 71f53017b7
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -15,6 +15,9 @@ from utils.log import logger
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
return
if "重新绑定" in text:
@ -52,7 +55,7 @@ def telegram_warning(update: Update, text: str):
user = update.effective_user
message = update.effective_message
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)
@ -101,7 +104,7 @@ def error_callable(func: Callable) -> Callable:
else:
logger.warning("Cookie错误")
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
except TooManyRequests as exc:
logger.warning("查询次数太多(操作频繁) %s", exc)
@ -125,7 +128,7 @@ def error_callable(func: Callable) -> Callable:
logger.error("GenshinException")
logger.exception(exc)
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
except ReturnCodeError as exc: