mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-11 18:42:49 +00:00
29 lines
766 B
Python
29 lines
766 B
Python
import traceback
|
|
from typing import Any
|
|
|
|
from loguru import logger
|
|
|
|
|
|
class HttpException(Exception):
|
|
def __init__(
|
|
self, task_id: str, status_code: int, message: str = "", data: Any = None
|
|
):
|
|
self.message = message
|
|
self.status_code = status_code
|
|
self.data = data
|
|
# 获取异常堆栈信息
|
|
tb_str = traceback.format_exc().strip()
|
|
if not tb_str or tb_str == "NoneType: None":
|
|
msg = f"HttpException: {status_code}, {task_id}, {message}"
|
|
else:
|
|
msg = f"HttpException: {status_code}, {task_id}, {message}\n{tb_str}"
|
|
|
|
if status_code == 400:
|
|
logger.warning(msg)
|
|
else:
|
|
logger.error(msg)
|
|
|
|
|
|
class FileNotFoundException(Exception):
|
|
pass
|