2026-05-22 13:44:50 +08:00
|
|
|
|
"""支付模块异常定义(继承 AppError,由全局 handler 统一映射)。"""
|
2026-02-10 14:23:29 +08:00
|
|
|
|
|
2026-05-22 13:44:50 +08:00
|
|
|
|
from app.core.errors import AppError
|
2026-02-10 14:23:29 +08:00
|
|
|
|
|
2026-05-22 13:44:50 +08:00
|
|
|
|
_PAYMENT_CODE_MAP: dict[str, tuple[int, str]] = {
|
|
|
|
|
|
"PAYMENT_CONFIG_ERROR": (502, "PROVIDER_ERROR"),
|
|
|
|
|
|
"PAYMENT_CREATE_ERROR": (502, "PROVIDER_ERROR"),
|
|
|
|
|
|
"PAYMENT_NOTIFY_ERROR": (400, "BAD_REQUEST"),
|
|
|
|
|
|
"PAYMENT_QUERY_ERROR": (502, "PROVIDER_ERROR"),
|
|
|
|
|
|
"PAYMENT_ERROR": (400, "BAD_REQUEST"),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentError(AppError):
|
2026-02-10 14:23:29 +08:00
|
|
|
|
def __init__(self, message: str = "支付异常", code: str = "PAYMENT_ERROR"):
|
2026-05-22 13:44:50 +08:00
|
|
|
|
status_code, error_code = _PAYMENT_CODE_MAP.get(code, (400, code))
|
|
|
|
|
|
super().__init__(message, status_code=status_code, error_code=error_code)
|
2026-02-10 14:23:29 +08:00
|
|
|
|
self.code = code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentConfigError(PaymentError):
|
|
|
|
|
|
def __init__(self, message: str = "支付配置错误"):
|
|
|
|
|
|
super().__init__(message=message, code="PAYMENT_CONFIG_ERROR")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentCreateError(PaymentError):
|
|
|
|
|
|
def __init__(self, message: str = "创建支付订单失败"):
|
|
|
|
|
|
super().__init__(message=message, code="PAYMENT_CREATE_ERROR")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentNotifyError(PaymentError):
|
|
|
|
|
|
def __init__(self, message: str = "支付回调处理失败"):
|
|
|
|
|
|
super().__init__(message=message, code="PAYMENT_NOTIFY_ERROR")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentQueryError(PaymentError):
|
|
|
|
|
|
def __init__(self, message: str = "查询支付状态失败"):
|
|
|
|
|
|
super().__init__(message=message, code="PAYMENT_QUERY_ERROR")
|