feat(proxy): T-P0 代理层骨架(包结构/DDL/门控挂载/单进程校验)
- gateway/proxy/ 十文件:config(ProxyConfig:元->毫元加载期换算 D-P1、差异化售价、 桶/峰谷/限流/semcache 配置)/ errors(8 类 HTTP 语义异常)/ ledger(四表两索引 DDL, WAL,ReviewQueue 连接纪律)/ auth·pricing·normalizer·semcache·upstream(§6 签名占位) / routes(/proxy/v1/models OpenAI 形状)/ __init__(build_proxy_router 组装点) - settings DEFAULTS 增 proxy 段(enabled 默认 False,D-P7) - api.py 首次 include_router(enabled 门控 + 装配失败不拖垮主应用) - serve.py workers>1 拒绝启动(D-P9:WEB_CONCURRENCY/UVICORN_WORKERS 校验) - 测试 +4(门控 404/DDL 幂等/毫元换算/池模型列表),全量 322 passed
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""代理层错误类型(§5.3 错误码映射)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class ProxyError(Exception):
|
||||
"""代理层错误基类(HTTP 语义由子类表达)。"""
|
||||
status_code = 500
|
||||
code = "proxy_error"
|
||||
|
||||
|
||||
class ProxyAuthError(ProxyError):
|
||||
"""无效/注销 key。"""
|
||||
status_code = 401
|
||||
code = "invalid_key"
|
||||
|
||||
|
||||
class BalanceError(ProxyError):
|
||||
"""余额或日上限不足(预扣失败)。"""
|
||||
status_code = 402
|
||||
code = "insufficient_balance"
|
||||
|
||||
|
||||
class SuspendedError(ProxyError):
|
||||
"""学生账户被停用。"""
|
||||
status_code = 403
|
||||
code = "student_suspended"
|
||||
|
||||
|
||||
class QuotaError(ProxyError):
|
||||
"""限流(rpm / 日请求上限 / 并发上限)。"""
|
||||
status_code = 429
|
||||
code = "rate_limited"
|
||||
|
||||
|
||||
class BodyTooLargeError(ProxyError):
|
||||
"""请求体超过 max_body_chars。"""
|
||||
status_code = 413
|
||||
code = "body_too_large"
|
||||
|
||||
|
||||
class UpstreamError(ProxyError):
|
||||
"""上游失败(首 token 前 failover 均失败)。"""
|
||||
status_code = 502
|
||||
code = "upstream_failed"
|
||||
|
||||
|
||||
class AdminAuthError(ProxyError):
|
||||
"""管理面鉴权失败。"""
|
||||
status_code = 401
|
||||
code = "admin_unauthorized"
|
||||
Reference in New Issue
Block a user