dingdanquanliucheng/backend/app/core/exceptions.py
taiyi 34e9be8912 为 core 层和 models 层添加中文注释
- 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>
2026-05-30 06:57:21 +08:00

24 lines
730 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""全局业务异常定义。
所有业务层抛出的异常统一使用 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)