Provides a centralized framework for defining and throwing business-specific exceptions with standardized error codes and HTTP status mapping. Use this to ensure consistent error reporting across backend services.
# Source: https://github.com/kuaigeyun/kuaigeyun-mes | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""
统一异常处理模块
定义所有业务异常类和错误码,提供统一的错误处理机制
"""
from typing import Optional, Dict, Any
from fastapi import HTTPException
class RiverEdgeException(Exception):
"""
RiverEdge 基础异常类
所有自定义异常都继承此类,提供统一的错误处理接口
"""
def __init__(
self,
message: str,
code: str,
status_code: int = 500,
details: Optional[Dict[str, Any]] = None
):
"""
初始化异常
Args:
message: 错误消息
code: 错误码
status_code: HTTP 状态码
details: 额外详细信息
"""
super().__init__(message)
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key