返回 MoneyPrinterTurbo
exception.py
根目录 / app / models / exception.py
1 import traceback
2 from typing import Any
3
4 from loguru import logger
5
6
7 class HttpException(Exception):
8 def __init__(
9 self, task_id: str, status_code: int, message: str = "", data: Any = None
10 ):
11 self.message = message
12 self.status_code = status_code
13 self.data = data
14 # Retrieve the exception stack trace information.
15 tb_str = traceback.format_exc().strip()
16 if not tb_str or tb_str == "NoneType: None":
17 msg = f"HttpException: {status_code}, {task_id}, {message}"
18 else:
19 msg = f"HttpException: {status_code}, {task_id}, {message}\n{tb_str}"
20
21 if status_code == 400:
22 logger.warning(msg)
23 else:
24 logger.error(msg)
25
26
27 class FileNotFoundException(Exception):
28 pass
29
29 lines PYTHON