- core: config、security、exceptions、responses、error_codes、db、main - models: base、business(17个模型类)、system(6个模型类)、__init__ - 每个函数和类均标注作用、返回值、被调用方 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
24 lines
730 B
Python
24 lines
730 B
Python
"""全局业务异常定义。
|
||
|
||
所有业务层抛出的异常统一使用 AppException,
|
||
由 main.py 中的全局异常处理器捕获并返回标准格式的 JSON 响应。
|
||
"""
|
||
|
||
|
||
class AppException(Exception):
|
||
"""项目统一业务异常。
|
||
|
||
在 Service 层和路由层抛出,由全局异常处理器统一捕获。
|
||
|
||
Attributes:
|
||
code: 业务错误码,对应 ErrorCode 常量。
|
||
message: 面向用户的错误提示信息。
|
||
status_code: HTTP 状态码,默认 400。
|
||
"""
|
||
|
||
def __init__(self, code: int, message: str, status_code: int = 400) -> None:
|
||
self.code = code
|
||
self.message = message
|
||
self.status_code = status_code
|
||
super().__init__(message)
|