Skip to content

Commit

Permalink
🔧 refactor(app): improve logging and exception handling
Browse files Browse the repository at this point in the history
- Changed `logger.warn` to `logger.warning` for better clarity.
- Added exception handling for `aiohttp` import to manage missing dependencies.

This enhances code readability and robustness.

#56
  • Loading branch information
sudoskys committed Jan 13, 2025
1 parent 5cc058b commit 0ef4e4a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/telegramify_markdown/interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
from typing import TYPE_CHECKING

import mistletoe

from loguru import logger

from telegramify_markdown.mermaid import render_mermaid
from telegramify_markdown.mime import get_filename
from telegramify_markdown.type import TaskType, File, Text, Photo, SentType, ContentTrace

if TYPE_CHECKING:
from aiohttp import ClientSession
try:
from aiohttp import ClientSession
except ImportError:
ClientSession = None


class BaseInterpreter(object):
Expand Down Expand Up @@ -47,7 +50,7 @@ async def render_task(self,
"""
task_type, token_pairs = task
if task_type != "base":
logger.warn("Invalid task type for BaseInterpreter.")
logger.warning("Invalid task type for BaseInterpreter.")
token1_l = list(__token1 for __token1, __token2 in token_pairs)
token2_l = list(__token2 for __token1, __token2 in token_pairs)
# 处理超过最大字数限制的情况
Expand Down Expand Up @@ -182,7 +185,7 @@ async def render_task(self,
)
message = f"[edit in mermaid.live]({url})"
except Exception as e:
logger.warn(f"Mermaid render error: {e}")
logger.warning(f"Mermaid render error: {e}")
return [
File(
file_name="invalid_mermaid.txt",
Expand Down

0 comments on commit 0ef4e4a

Please sign in to comment.